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 34ab358 commit be4fb1cCopy full SHA for be4fb1c
valid-anagram/hyer0705.ts
@@ -0,0 +1,20 @@
1
+function isAnagram(s: string, t: string): boolean {
2
+ if (s.length !== t.length) return false;
3
+
4
+ const sCountMap = new Map<string, number>();
5
+ const tCountMap = new Map<string, number>();
6
7
+ for (let i = 0; i < s.length; i++) {
8
+ const currentS = s[i];
9
+ const currentT = t[i];
10
11
+ sCountMap.set(currentS, (sCountMap.get(currentS) || 0) + 1);
12
+ tCountMap.set(currentT, (tCountMap.get(currentT) || 0) + 1);
13
+ }
14
15
+ for (const [k, v] of sCountMap) {
16
+ if (!tCountMap.has(k) || tCountMap.get(k) !== v) return false;
17
18
19
+ return true;
20
+}
0 commit comments