class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
hash = {}
for i in range(len(strs)):
s = sorted(strs[i])
j = "".join(s)
hash[strs[i]] = j
dic = {}
for k in hash.keys():
v = hash[k]
if v in dic:
dic[v].append(k)
else:
dic[v] = [k]
result = list(dic.values())
print(result)
我获得的结果是,[[阿纳克]、[u bat]、[u ate 、u tea 、u food]注意到每一份清单中出现一个u是如何用尽可能少的记忆解决这一问题的。