Skip to content

Commit 317a696

Browse files
committed
valid anagram solution
1 parent c1c5103 commit 317a696

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-anagram/jiunshinn.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# time complexity O(n)
2+
# space complexity O(n)
3+
4+
5+
class Solution:
6+
def isAnagram(self, s: str, t: str) -> bool:
7+
if len(s) != len(t):
8+
return False
9+
10+
counter_s = {}
11+
counter_t = {}
12+
13+
for char in s:
14+
counter_s[char] = counter_s.get(char, 0) + 1
15+
16+
for char in t:
17+
counter_t[char] = counter_t.get(char, 0) + 1
18+
19+
if counter_s == counter_t:
20+
return True
21+
else:
22+
return False

0 commit comments

Comments
 (0)