-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from GUMUNYEONG/main
[구문영(GUMUNYEONG)] WEEK 2 Solution
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @param {string} s | ||
* @param {string} t | ||
* @return {boolean} | ||
*/ | ||
var isAnagram = function (s, t) { | ||
const countHash = {}; | ||
|
||
if (s.length !== t.length) return false; | ||
|
||
for (str_t of t) { | ||
countHash[str_t] ? countHash[str_t]++ : countHash[str_t] = 1; | ||
} | ||
|
||
for (str_s of s) { | ||
if (countHash[str_s]) { | ||
countHash[str_s]--; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
// TC : O(n) | ||
// n(=s의 길이 = t의 길이) 만큼 반복 하므로 On(n) | ||
|
||
// SC : O(n) | ||
// 최대크기 n(=s의 길이 = t의 길이)만큼인 객체를 생성하므로 공간 복잡도도 O(n) |