Skip to main content

49. Group Anagrams - LeetCode

ยท One min read
class Solution:
def groupAnagrams(self, strs: list[str]) -> list[list[str]]:
ht: dict[str, list[str]] = {}
for s in strs:
key = ''.join(sorted((s)))
ht[key] = ht.get(key, [])
ht[key].append(s)
return list(ht.values())