We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 92c26f7 commit e3153bcCopy full SHA for e3153bc
vs-lt/242.有效的字母异位词.js
@@ -0,0 +1,31 @@
1
+/*
2
+ * @lc app=leetcode.cn id=242 lang=javascript
3
+ *
4
+ * [242] 有效的字母异位词
5
+ */
6
+
7
+// @lc code=start
8
+/**
9
+ * @param {string} s
10
+ * @param {string} t
11
+ * @return {boolean}
12
13
+var isAnagram = function (s, t) {
14
+ if (s.length !== t.length) return false;
15
16
+ const sMap = Array(26).fill(0);
17
+ for (let i = 0; i < s.length; i++) {
18
+ const index = s[i].charCodeAt() - 97;
19
+ sMap[index]++;
20
+ }
21
+ for (let i = 0; i < t.length; i++) {
22
+ const index = t[i].charCodeAt() - 97;
23
+ sMap[index]--;
24
+ if (sMap[index] < 0) {
25
+ return false;
26
27
28
+ return true;
29
+};
30
+// @lc code=end
31
0 commit comments