Skip to content
Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions valid-anagram/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isAnagram = function (s, t) {
const countHash = {};
let result = true;

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 {
result = false;
break;
}
}

return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요렇게 하시면 더 깔끔하고 효율적인 코드가 되지 않을까 생각이 들었습니다 :)

Suggested change
} else {
result = false;
break;
}
}
return result;
} else {
return false;
}
}
return true;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 더 간단하게 표현할 수 있었네요..! 피드백 감사합니다! :>

};

// TC : O(n)
// n(=s의 길이 = t의 길이) 만큼 반복 하므로 On(n)

// SC : O(n)
// 최대크기 n(=s의 길이 = t의 길이)만큼인 객체를 생성하므로 공간 복잡도도 O(n)