Skip to content
Open
Changes from all 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
14 changes: 14 additions & 0 deletions valid-anagram/jthw1005.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Bit Manipulation
  • 설명: 두 문자열의 알파벳 등장 횟수를 배열로 세서 차이가 0인지 확인하는 방식으로 문자열 간 동형 여부를 판별합니다. 해시 맵 대신 고정 크기 배열로 카운트를 관리하는 패턴과 간단한 비트 조작은 사용되지 않지만 문자 인덱스를 이용한 카운트 방식이 핵심입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n + m)
Space O(1)

피드백: 정렬 없이 고정 길이 배열로 알파벳 개수 차이를 비교하는 효율적인 해법이다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const isAnagram = (s, t) => {
const data = new Array(26).fill(0);
const a_ascii = 'a'.charCodeAt();

for (const char of s) {
data[char.charCodeAt() - a_ascii]++;
}

for (const char of t) {
data[char.charCodeAt() - a_ascii]--;
}

return !data.some((el) => el !== 0);
};
Loading