其他分享
首页 > 其他分享> > 查找表_leetcode49

查找表_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)

标签:temp,strs,res,List,leetcode49,查找,ans,append
来源: https://www.cnblogs.com/lux-ace/p/10546906.html