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 f8d1d3a commit 04d2b92Copy full SHA for 04d2b92
valid-anagram/sukyoungshin.ts
@@ -0,0 +1,28 @@
1
+// 1번풀이 (hashTable)
2
+function isAnagram1(s: string, t: string): boolean {
3
+ if (s.length !== t.length) return false;
4
+
5
+ const charCount: Record<string, number> = {};
6
7
+ for (const char of s) {
8
+ charCount[char] = (charCount[char] ?? 0) + 1;
9
+ }
10
11
+ for (const char of t) {
12
+ if (!charCount[char]) return false;
13
+ charCount[char]--;
14
15
16
+ return true;
17
+};
18
19
+// 2번풀이 (sort)
20
+function isAnagram2(s: string, t: string): boolean {
21
22
23
+ const sortedS = s.split('').sort().join('');
24
+ const sortedT = t.split('').sort().join('');
25
26
+ return sortedS === sortedT;
27
28
0 commit comments