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 e55594c commit c6d37afCopy full SHA for c6d37af
valid-anagram/gitsunmin.ts
@@ -0,0 +1,22 @@
1
+/**
2
+ * https://leetcode.com/problems/valid-anagram/submissions
3
+ * time complexity : O(n)
4
+ * space complexity : O(n)
5
+ */
6
+function isAnagram(s: string, t: string): boolean {
7
+ if (s.length !== t.length) return false;
8
+
9
+ const map = {};
10
11
+ for (const char of s) map[char] = (map[char] ?? 0) + 1;
12
13
+ for (const char of t) {
14
+ if (map[char] !== undefined) {
15
+ map[char] = map[char] - 1;
16
+ } else return false;
17
+ }
18
19
+ for (const val of Object.values(map)) if (val !== 0) return false;
20
21
+ return true;
22
+};
0 commit comments