Skip to content

[구문영(GUMUNYEONG)] WEEK 2 Solution #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 25, 2024
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)