Skip to content

Commit 0b3e1dd

Browse files
add 242 solution[js]
1 parent 83c08d8 commit 0b3e1dd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const isAnagram = function(s,t){
2+
let a = {}, b = {};
3+
for(let i = 0 ; i < s.length; i++){
4+
if(a.hasOwnProperty(s[i])){
5+
a[s[i]]++;
6+
}else{
7+
a[s[i]] = 1;
8+
}
9+
}
10+
for(let i = 0 ; i < t.length; i++){
11+
if(b.hasOwnProperty(t[i])){
12+
b[t[i]]++;
13+
}else{
14+
b[t[i]] = 1;
15+
}
16+
}
17+
let keyA = Object.keys(a);
18+
let keyB = Object.keys(b);
19+
if(keyA.length !== keyB.length){
20+
return false;
21+
}
22+
for(let i = 0; i < keyA.length; i++){
23+
if(a[keyA[i]] !== b[keyA[i]]) return false;
24+
}
25+
return true;
26+
}

0 commit comments

Comments
 (0)