查找表_leetcode49
Posted AceKo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查找表_leetcode49相关的知识,希望对你有一定的参考价值。
class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
ans, res, ret = [], {}, []
for s in strs:
temp = list(s)
temp.sort()
ans.append("".join(temp))
for i in range(len(ans)):
if ans[i] not in res:
res[ans[i]] = []
res[ans[i]].append(strs[i])
for key in res:
ret.append(res[key])
return ret
strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
s = Solution()
print s.groupAnagrams(strs)
以上是关于查找表_leetcode49的主要内容,如果未能解决你的问题,请参考以下文章