class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
anagram_dict,result=collections.defaultdict(list),[]
for string in strs:
sorted_str=''.join(sorted(string))
anagram_dict[sorted_str].append(string)
for anagram in anagram_dict.values():
result.append(anagram)
return result
网友评论