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 7f70da2 commit 335b962Copy full SHA for 335b962
valid-anagram/prgmr99.js
@@ -0,0 +1,33 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {string} t
4
+ * @return {boolean}
5
+ */
6
+var isAnagram = function (s, t) {
7
+ const stringMap = new Map();
8
+
9
+ if (s.length !== t.length) return false;
10
11
+ for (let i = 0; i < s.length; i++) {
12
+ const currentValue = stringMap.get(s[i]);
13
14
+ if (currentValue) {
15
+ stringMap.set(s[i], currentValue + 1);
16
+ } else {
17
+ stringMap.set(s[i], 1);
18
+ }
19
20
21
+ for (let i = 0; i < t.length; i++) {
22
+ const currentValue = t[i];
23
+ const currentValueInStringMap = stringMap.get(currentValue);
24
25
+ if (currentValueInStringMap) {
26
+ stringMap.set(currentValue, currentValueInStringMap - 1);
27
28
+ return false;
29
30
31
32
+ return true;
33
+};
0 commit comments