Back to course home
0% completed
Vote For New Content
Brute Force Solution
Thai Minh
Jul 30, 2023
class Solution: def isAnagram(self, s, t): # TODO: Write your code here # create dict for string s # check char of t for s dict if it is not in s then false s_dict = {} for ch in s: s_dict[ch] = s_dict.get(ch, 0) + 1 for ch in t: if ch not in s: return False elif ch in s and s_dict[ch] - 1 < 0: return False else: s_dict[ch] -= 1 return True
0
0
Comments
Comments