Skip to content
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)