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 fdf3120 commit 10b06b9Copy full SHA for 10b06b9
valid-anagram/soobing.ts
@@ -0,0 +1,17 @@
1
+function isAnagram(s: string, t: string): boolean {
2
+ const map = new Map();
3
+ for (let i = 0; i < s.length; i++) {
4
+ map.set(s[i], (map.get(s[i]) || 0) + 1);
5
+ }
6
+ for (let i = 0; i < t.length; i++) {
7
+ if (!map.has(t[i])) {
8
+ return false;
9
10
+ const newCount = map.get(t[i]) - 1;
11
+ if (newCount < 0) return false;
12
+ if (newCount === 0) map.delete(t[i]);
13
+ else map.set(t[i], map.get(t[i]) - 1);
14
15
+
16
+ return map.size === 0;
17
+}
0 commit comments