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 b00545f commit bfee821Copy full SHA for bfee821
1 file changed
valid-anagram/jjipper.ts
@@ -0,0 +1,28 @@
1
+/**
2
+ * https://leetcode.com/problems/valid-anagram/
3
+ * time complexity : O(n)
4
+ * space complexity : O(n)
5
+ */
6
+
7
+function isAnagram(s: string, t: string): boolean {
8
+ const count: Record<string, number> = {};
9
+ if (s.length !== t.length) return false;
10
11
+ for (let char of s) {
12
+ if (count[char] === undefined) {
13
+ count[char] = 1;
14
+ } else {
15
+ count[char] += 1;
16
+ }
17
18
19
+ for (let char of t) {
20
+ if (!count[char]) {
21
+ return false;
22
23
+ count[char] -= 1;
24
25
26
27
+ return Object.values(count).every(v => v === 0);
28
+};
0 commit comments