mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加242.有效的字母异位词JavaScript版本
This commit is contained in:
@ -140,6 +140,23 @@ func isAnagram(s string, t string) bool {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
javaScript:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var isAnagram = function(s, t) {
|
||||||
|
const resSet = new Array(25).fill(0);
|
||||||
|
const base = "a".charCodeAt();
|
||||||
|
for(const i of s) {
|
||||||
|
resSet[i.charCodeAt() - base]++;
|
||||||
|
}
|
||||||
|
for(const i of t) {
|
||||||
|
resSet[i.charCodeAt() - base]--;
|
||||||
|
// if(val < 0) return false;
|
||||||
|
}
|
||||||
|
return resSet.every(i => !i);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
## 相关题目
|
## 相关题目
|
||||||
|
|
||||||
* 383.赎金信
|
* 383.赎金信
|
||||||
|
Reference in New Issue
Block a user