242. Valid Anagram
Easy
Problem:
Input: s = "anagram", t = "nagaram"
Output: trueInput: s = "rat", t = "car"
Output: false
Solution:
Hash Table
import collections
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
s_dict = collections.defaultdict(int)
t_dict = collections.defaultdict(int)
if len(s) == len(t):
for idx in range(len(s)):
s_dict[s[idx]] += 1
t_dict[t[idx]] += 1
for char in s:
if s_dict[char] != t_dict[char]:
return False
else:
return False
return True
Pythonic way

Last updated