242. Valid Anagram
# Easy
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if len(s) != len(t):
return False
m = {}
for x in s:
if x not in m:
m[x] = 1
else:
m[x] += 1
for y in t:
if (y not in m) or m[y] == 0:
return False
m[y] -= 1
return True
Last updated
Was this helpful?