Skip to content

Commit cbbad7b

Browse files
committed
Valid Anagram
1 parent e0f5aa7 commit cbbad7b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-anagram/casentino.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function isAnagram(s: string, t: string): boolean {
2+
if (s.length !== t.length) {
3+
return false;
4+
}
5+
const count = new Array(26).fill(0);
6+
for (let i = 0; i < s.length; i++) {
7+
count[s.charCodeAt(i) - 97]++;
8+
count[t.charCodeAt(i) - 97]--;
9+
}
10+
for (let c of count) {
11+
if (c !== 0) {
12+
return false;
13+
}
14+
}
15+
return true;
16+
}

0 commit comments

Comments
 (0)