Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa54a20

Browse files
authored
Create 242-Valid-Anagram.js
1 parent ae438f7 commit aa54a20

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

javascript/242-Valid-Anagram.js

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

0 commit comments

Comments
 (0)