Skip to content

Commit c00f407

Browse files
committed
feat: valid-anagram 풀이
1 parent 4803e42 commit c00f407

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

valid-anagram/jinah92.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 공간복잡도: O(n), 시간복잡도: O(n)
2+
class Solution:
3+
def isAnagram(self, s: str, t: str) -> bool:
4+
char_set_1, char_set_2 = {}, {}
5+
6+
for ch in s:
7+
char_set_1[ch] = 0 if ch not in char_set_1 else char_set_1[ch] + 1
8+
9+
for ch in t:
10+
char_set_2[ch] = 0 if ch not in char_set_2 else char_set_2[ch] + 1
11+
12+
# dictionary의 모든 요소 종류와 개수가 일치해야 함
13+
return char_set_1 == char_set_2

0 commit comments

Comments
 (0)