mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
更新242.有效的字母异位词,js方法,采用map
This commit is contained in:
@ -205,6 +205,19 @@ var isAnagram = function(s, t) {
|
||||
}
|
||||
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:
|
||||
|
Reference in New Issue
Block a user