diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md index 10939b0f..8aa0d171 100644 --- a/problems/0242.有效的字母异位词.md +++ b/problems/0242.有效的字母异位词.md @@ -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.赎金信