Skip to content

Commit 35e0c54

Browse files
committed
feat: Add Valid Anagram solutions
1 parent 2fd0eef commit 35e0c54

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

valid-anagram/thispath98.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
class Solution:
3+
def isAnagram(self, s: str, t: str) -> bool:
4+
"""
5+
Time Complexity:
6+
O(N log N):
7+
두 string을 정렬, 이는 보통 quick sort로 구현되어
8+
N log N 만큼 소요된다.
9+
10+
Space Complexity:
11+
O(N):
12+
최악의 경우 (모든 string이 유일할 경우) N개의 리스트
13+
를 저장한다.
14+
"""
15+
return sorted(s) == sorted(t)
16+
17+
def isAnagramCounter(self, s: str, t: str) -> bool:
18+
"""
19+
Time Complexity:
20+
O(N):
21+
해시를 기반으로 일치 여부 탐색, N개의 엔트리를
22+
한번씩 순회하는 것으로 구현된다.
23+
24+
Space Complexity:
25+
O(N):
26+
최악의 경우 (모든 string이 유일할 경우) N개의 리스트
27+
를 저장한다.
28+
"""
29+
from collections import Counter
30+
31+
return Counter(s) == Counter(t)

0 commit comments

Comments
 (0)