Skip to content

Commit f0fe78b

Browse files
author
이호찬
committed
valid-anagram solution
1 parent a6a966b commit f0fe78b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

valid-anagram/lhc0506.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} t
4+
* @return {boolean}
5+
*/
6+
var isAnagram = function(s, t) {
7+
if (s.length !== t.length) {
8+
return false;
9+
}
10+
11+
const charCountMap = {};
12+
13+
for (let char of s) {
14+
charCountMap[char] = (charCountMap[char] || 0) + 1;
15+
}
16+
17+
for (let char of t) {
18+
if (!charCountMap[char]) {
19+
return false;
20+
}
21+
22+
charCountMap[char] -= 1;
23+
}
24+
25+
return true;
26+
};

0 commit comments

Comments
 (0)