Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def group Anagrams(self, strs: List[str]) -> List[List[str]]:
- res = defaultdict(list) # mapping charCount to list of Anagrams
- for s in strs:
- count = [0] * 26 # a ... z
- for c in s:
- count[ord(c) - ord("a")] += 1
- res[tuple(count)].append(s)
- return res.values()
Advertisement
Add Comment
Please, Sign In to add comment