Skip to content

Commit 91742b0

Browse files
committed
feat: valid-anagram solution
1 parent 026e627 commit 91742b0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

valid-anagram/YeomChaeEun.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function isAnagram(s: string, t: string): boolean {
2+
if(s.length !== t.length) return false
3+
4+
let counter = {}
5+
for(let sValue of s) {
6+
if(!counter[sValue]) { counter[sValue] = 1 }
7+
else { counter[sValue]++ }
8+
9+
}
10+
11+
for(let tValue of t) {
12+
if(!counter[tValue]) return false
13+
else counter[tValue]--
14+
}
15+
16+
return Object.values(counter).findIndex(value => value !== 0) < 0;
17+
};

0 commit comments

Comments
 (0)