Skip to content

Commit 45ea72e

Browse files
authored
Merge pull request #357 from GUMUNYEONG/main
[구문영(GUMUNYEONG)] WEEK 2 Solution
2 parents f02b7bf + c690fd8 commit 45ea72e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

valid-anagram/GUMUNYEONG.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} t
4+
* @return {boolean}
5+
*/
6+
var isAnagram = function (s, t) {
7+
const countHash = {};
8+
9+
if (s.length !== t.length) return false;
10+
11+
for (str_t of t) {
12+
countHash[str_t] ? countHash[str_t]++ : countHash[str_t] = 1;
13+
}
14+
15+
for (str_s of s) {
16+
if (countHash[str_s]) {
17+
countHash[str_s]--;
18+
} else {
19+
return false;
20+
}
21+
}
22+
23+
return true;
24+
};
25+
26+
// TC : O(n)
27+
// n(=s의 길이 = t의 길이) 만큼 반복 하므로 On(n)
28+
29+
// SC : O(n)
30+
// 최대크기 n(=s의 길이 = t의 길이)만큼인 객체를 생성하므로 공간 복잡도도 O(n)

0 commit comments

Comments
 (0)