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 9c2807c commit bbe31a4Copy full SHA for bbe31a4
easy/242-valid-anagram.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {string} t
4
+ * @return {boolean}
5
+ */
6
+ var isAnagram = function(s, t) {
7
+ if (s === "" || t === "") return true;
8
+ if (s.length !== t.length) return false;
9
+
10
+ const map = {};
11
+ for (let i=0; i<s.length; i++) {
12
+ const l = s[i];
13
+ if (!map[l]) map[l] = 0;
14
+ map[l]++;
15
+ }
16
+ for (let i=0; i<t.length; i++) {
17
+ const l = t[i];
18
+ if (map[l]) {
19
+ map[l]--;
20
+ if (map[l] === 0) {
21
+ delete map[l];
22
23
24
25
+ return !Object.keys(map).length;
26
+};
0 commit comments