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 bcde25c commit 2f8a34bCopy full SHA for 2f8a34b
valid-anagram/gwbaik9717.js
@@ -0,0 +1,39 @@
1
+// Time complexity: O(n)
2
+// Space complexity: O(n)
3
+
4
+/**
5
+ * @param {string} s
6
+ * @param {string} t
7
+ * @return {boolean}
8
+ */
9
+var isAnagram = function (s, t) {
10
+ if (s.length !== t.length) {
11
+ return false;
12
+ }
13
14
+ const createDictFromString = (str) => {
15
+ const dict = new Map();
16
17
+ for (const chr of str) {
18
+ if (dict.has(chr)) {
19
+ dict.set(chr, dict.get(chr) + 1);
20
+ continue;
21
22
23
+ dict.set(chr, 1);
24
25
26
+ return dict;
27
+ };
28
29
+ const dictS = createDictFromString(s);
30
+ const dictT = createDictFromString(t);
31
32
+ for (const [key, value] of dictS) {
33
+ if (dictT.get(key) !== value) {
34
35
36
37
38
+ return true;
39
+};
0 commit comments