We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b82b4eb commit 9fcc0bcCopy full SHA for 9fcc0bc
valid-anagram/Chaedie.py
@@ -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
27
0 commit comments