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
7 changes: 7 additions & 0 deletions valid-anagram/njngwn.py

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, Dynamic Programming
  • 설명: 두 문자열의 문자 분포를 카운트로 비교하는 방식으로 해시 맵/카운터를 활용합니다. 동일한 다항의 문자가 같아야 하므로 해시 기반 비교 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n) O(n + m)
Space O(k) O(k)

피드백: 선언부에 대한 의존 없이 두 문자열의 문자 분포를 Counter로 비교한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from collections import Counter

class Solution:
# Time Complexity: O(n), n: max(len(s), len(t))
# Space Complexity: O(k), k: number of letters
def isAnagram(self, s: str, t: str) -> bool:
return Counter(s) == Counter(t)

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.

안녕하세요 이번주 리뷰를 맡게되었습니다 :)

Counter라는게 있군요? 엄청 깔끔하네요!
찾아보니 이게 문자열 돌면서 맵을 만들어주는 함수인 것 같네요.

그런데 len로 길이가 다른 경우 리턴하도록 체크를 먼저 해 주면, 불필요하게 맵을 만드는 비용을 줄일 수 있을 것 같아요.

Loading