Valid Anagram
Problem
Given two strings s and t , write a function to determine if t is an anagram of s.
Solution
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
dic1, dic2 = {}, {}
for letter in s:
if letter not in dic1:
dic1[letter] = 0
dic1[letter]+=1
for letter in t:
if letter not in dic2:
dic2[letter] = 0
dic2[letter]+=1
return dic1 == dic2
Last updated
Was this helpful?