Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def isAnagram(self, s: str, t: str) -> bool:
- """ Solution: We can use a dict to keep track of the counts of each
- character in each string, and then iterate through the alphabet to
- check each character to make sure the count is the same.
- """
- s_count = dict()
- t_count = dict()
- for c in s:
- if c in s_count:
- s_count[c] += 1
- else:
- s_count[c] = 1
- for c in t:
- if c in t_count:
- t_count[c] += 1
- else:
- t_count[c] = 1
- for c in 'abcdefghijklmnopqrstuvwxyz':
- if s_count.get(c) != t_count.get(c):
- return False
- return True
Advertisement
Add Comment
Please, Sign In to add comment