We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aae15b9 commit a9c1996Copy full SHA for a9c1996
valid-anagram/hoyeongkwak.ts
@@ -0,0 +1,17 @@
1
+function isAnagram(s: string, t: string): boolean {
2
+ // 시간복잡도 O(nlogn), 공간복잡도 O(n)
3
+ // const sSorted = s.split('').sort().join(',')
4
+ // const tSorted = t.split('').sort().join(',')
5
+ // return sSorted === tSorted
6
+
7
+ /*
8
+ 시간복잡도 O(n), 공간복잡도 O(1)
9
+ */
10
+ if (s.length != t.length) return false
11
+ const count = new Array(26).fill(0)
12
+ for (let i = 0; i < s.length; i++) {
13
+ count[s.charCodeAt(i) - 97]++
14
+ count[t.charCodeAt(i) - 97]--
15
+ }
16
+ return count.every(c => c === 0)
17
+};
0 commit comments