mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
更新242.有效的字母异位词,js方法,采用map
This commit is contained in:
@ -205,6 +205,19 @@ var isAnagram = function(s, t) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var isAnagram = function(s, t) {
|
||||||
|
if(s.length !== t.length) return false;
|
||||||
|
let char_count = new Map();
|
||||||
|
for(let item of s) {
|
||||||
|
char_count.set(item, (char_count.get(item) || 0) + 1) ;
|
||||||
|
}
|
||||||
|
for(let item of t) {
|
||||||
|
if(!char_count.get(item)) return false;
|
||||||
|
char_count.set(item, char_count.get(item)-1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript:
|
TypeScript:
|
||||||
|
Reference in New Issue
Block a user