您的位置:首页 > 其它

Leetcode 49 Group Anagrams

2017-06-07 23:44 387 查看
Leetcode 49 Group Anagrams

第一段用python做的题,工具用称手是真好啊。

class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
c_set = {}
for s in strs:
ch_list = []
for ch in s:
ch_list.append(ch)
ch_list.sort()
c = "".join(ch_list)
if c in c_set:
c_set[c].append(s)
else:
c_set[c] = []
c_set[c].append(s)
res = []
for k in c_set:
res.append(c_set[k])
print res
return res
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: