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 333d742 commit b43cfb8Copy full SHA for b43cfb8
โvalid-anagram/uraflower.jsโ
@@ -0,0 +1,27 @@
1
+/**
2
+ * ๋ ๋ฌธ์์ด์ด ์ ๋๊ทธ๋จ์ธ์ง ์ฌ๋ถ๋ฅผ ๋ฐํํ๋ ํจ์
3
+ * @param {string} s
4
+ * @param {string} t
5
+ * @return {boolean}
6
+ */
7
+const isAnagram = function (s, t) {
8
+ if (s.length !== t.length) return false;
9
+
10
+ const counter = Array.from(s).reduce((counter, char) => {
11
+ counter[char] = counter[char] + 1 || 1;
12
+ return counter;
13
+ }, {});
14
15
+ for (let char of t) {
16
+ if (!counter[char] || counter[char] === 0) {
17
+ return false;
18
+ }
19
20
+ counter[char] -= 1;
21
22
23
+ return true;
24
+};
25
26
+// ์๊ฐ๋ณต์ก๋: O(n)
27
+// ๊ณต๊ฐ๋ณต์ก๋: O(n)
0 commit comments