添加242.有效的字母异位词JavaScript版本
This commit is contained in:
parent
57d80b626f
commit
fc04e9ec1e
|
|
@ -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.赎金信
|
||||
|
|
|
|||
Loading…
Reference in New Issue