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 f639445 commit dfe8f0fCopy full SHA for dfe8f0f
valid-anagram/solbijae.ts
@@ -0,0 +1,17 @@
1
+function isAnagram(s: string, t: string): boolean {
2
+ // 첫 시도: 시간 복잡도 O(n log n), 공간 복잡도 O(n)
3
+ // const sSort = s.split('').sort();
4
+ // const tSort = t.split('').sort();
5
+ // return JSON.stringify(sSort) === JSON.stringify(tSort);
6
+
7
+ // 시간 복잡도 O(n), 공간복잡도 O(1)
8
+ if (s.length !== t.length) return false;
9
10
+ const count = new Array(26).fill(0);
11
+ for (let i=0; i<s.length; i++) {
12
+ count[s.charCodeAt(i) - 97]++;
13
+ count[t.charCodeAt(i) - 97]--;
14
+ }
15
16
+ return count.every(c => c === 0);
17
+};
0 commit comments