Skip to content

Commit 22e4088

Browse files
committed
2week: 242. Valid Anagram
1 parent b5b6294 commit 22e4088

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

valid-anagram/j2h30728.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function isAnagram(s: string, t: string): boolean {
2+
const obj = {};
3+
for (let i = 0; i < s.length; i++) {
4+
obj[s[i]] = (obj[s[i]] || 0) + 1;
5+
}
6+
7+
for (let i = 0; i < t.length; i++) {
8+
obj[t[i]] -= 1;
9+
}
10+
11+
return Object.values(obj).filter((value) => value !== 0).length === 0;
12+
}

0 commit comments

Comments
 (0)