From fc04e9ec1ee596adf438224e82633142871b676b Mon Sep 17 00:00:00 2001 From: "qingyi.liu" Date: Sat, 22 May 2021 10:16:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0242.=E6=9C=89=E6=95=88?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AF=8D=E5=BC=82=E4=BD=8D=E8=AF=8DJavaScrip?= =?UTF-8?q?t=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0242.有效的字母异位词.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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.赎金信