class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
# 思路:存一个map,map的key是字符串排序之后值
kv = {}
for item in strs:
if "".join(sorted(item)) not in kv:
kv["".join(sorted(item))] = [item]
else:
kv["".join(sorted(item))].append(item)
res = []
for key in kv:
res.append(kv[key])
return res
网友评论