解
- 字典
- key 为排序字符串
- value 为出现的第几个字母异位词
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
result = list()
# key 为排序字符串 value 为result的索引数 即出现的第几个字母异位词
dic = {}
for s in strs:
string = "".join(sorted(s))
if string not in dic:
dic[string] = len(result)
result.append([s])
else:
result[dic[string]].append(s)
return result