Skip to content

Commit cd5accd

Browse files
author
jinbeom
committed
Valid Anagram Solution
1 parent 0faaeae commit cd5accd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

valid-anagram/kayden.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 시간복잡도: O(N)
2+
# 공간복잡도: O(N)
3+
class Solution:
4+
def isAnagram(self, s: str, t: str) -> bool:
5+
if len(s) != len(t):
6+
return False
7+
8+
counter_s = {}
9+
for letter in s:
10+
counter_s[letter] = counter_s.get(letter, 0) + 1
11+
12+
counter_t = {}
13+
for letter in t:
14+
counter_t[letter] = counter_t.get(letter, 0) + 1
15+
16+
for letter, cnt in counter_s.items():
17+
if counter_t.get(letter, 0) != cnt:
18+
return False
19+
20+
return True

0 commit comments

Comments
 (0)