Skip to content

Commit 9fcc0bc

Browse files
committed
feat: [Week 02-1] solve valid-anagram
1 parent b82b4eb commit 9fcc0bc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

valid-anagram/Chaedie.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'''
2+
count a frequency of the character with a hash map
3+
s's character will be added and
4+
t's character will be subtracted
5+
6+
return True if count's min and max value is not a zero
7+
else return False
8+
9+
Time O(n)
10+
Space O(n)
11+
'''
12+
13+
class Solution:
14+
def isAnagram(self, s: str, t: str) -> bool:
15+
count = defaultdict(int)
16+
17+
if len(t) != len(s):
18+
return False
19+
20+
for i in range(len(s)):
21+
count[s[i]] += 1
22+
count[t[i]] -= 1
23+
24+
if max(count.values()) == 0:
25+
return True
26+
return False
27+

0 commit comments

Comments
 (0)