添加242.有效的字母异位词JavaScript版本

This commit is contained in:
qingyi.liu
2021-05-22 10:16:13 +08:00
parent 57d80b626f
commit fc04e9ec1e

View File

@ -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.赎金信