Skip to content

Commit 91e33fc

Browse files
author
keunsun.lee
committed
Week2. valid-anagram solution
1 parent 79de0bc commit 91e33fc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-anagram/sun912.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def isAnagram(self, s: str, t: str) -> bool:
3+
if len(s) != len(t):
4+
return False
5+
6+
count_s = {}
7+
count_t = {}
8+
9+
for i in range(len(s)):
10+
count_s[s[i]] = 1 + count_s.get(s[i], 0)
11+
count_t[t[i]] = 1 + count_t.get(t[i], 0)
12+
13+
for c in count_t:
14+
if count_t[c] != count_s.get(c, 0):
15+
return False
16+
return True

0 commit comments

Comments
 (0)