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 81d4e12 commit 33af494Copy full SHA for 33af494
valid-anagram/whewchews.ts
@@ -0,0 +1,21 @@
1
+function isAnagram(s: string, t: string): boolean {
2
+ // TC: O(1)
3
+ if (s.length !== t.length) return false;
4
+
5
+ // SC: O(N)
6
+ const count: { [key: string]: number } = {};
7
8
+ // TC: O(N)
9
+ for (let i = 0; i <= s.length - 1; i++) {
10
+ const sChar = s[i];
11
+ const tChar = t[i];
12
+ count[sChar] = (count[sChar] || 0) + 1;
13
+ count[tChar] = (count[tChar] || 0) - 1;
14
+ }
15
16
17
+ return Object.values(count).every((v) => v === 0);
18
+}
19
20
+// TC: O(N)
21
+// SC: O(N)
0 commit comments