242 Valid Anagram
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
class Solution:
|
||||
def isAnagram(self, s: str, t: str) -> bool:
|
||||
if len(s) != len(t):
|
||||
return False
|
||||
|
||||
s_dict = {}
|
||||
for c in s:
|
||||
s_dict[c] = s_dict.get(c, 0) + 1
|
||||
for c in t:
|
||||
s_dict[c] = s_dict.get(c, 0) - 1
|
||||
if s_dict[c] < 0:
|
||||
return False
|
||||
return True
|
||||
Reference in New Issue
Block a user