Skip to content

Commit 12e1701

Browse files
author
sejineer
committed
valid-anagram solution
1 parent b80c0da commit 12e1701

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

valid-anagram/sejineer.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
시간 복잡도: O(N)
3+
공간 복잡도: O(N)
4+
5+
코드 가독성 개선 코드:
6+
from collections import Counter
7+
8+
class Solution:
9+
def isAnagram(self, s: str, t: str) -> bool:
10+
return Counter(s) == Counter(t)
11+
"""
12+
from collections import Counter
13+
14+
class Solution:
15+
def isAnagram(self, s: str, t: str) -> bool:
16+
if len(s) != len(t):
17+
return False
18+
19+
s_counter = Counter(s)
20+
t_counter = Counter(t)
21+
22+
for num, freq in t_counter.items():
23+
if s_counter[num] != freq:
24+
return False
25+
26+
return True

0 commit comments

Comments
 (0)