Skip to content

Commit

Permalink
Merge pull request #357 from GUMUNYEONG/main
Browse files Browse the repository at this point in the history
[구문영(GUMUNYEONG)] WEEK 2 Solution
  • Loading branch information
GUMUNYEONG authored Aug 25, 2024
2 parents f02b7bf + c690fd8 commit 45ea72e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions valid-anagram/GUMUNYEONG.js
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)

0 comments on commit 45ea72e

Please sign in to comment.