Given an array of strings, group anagrams together.
For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],
Return:
[ ["ate", "eat","tea"], ["nat","tan"], ["bat"] ]
Note:
- For the return value, each inner list's elements must follow the lexicographic order.
- All inputs will be in lower-case.
class Solution(object):
def groupAnagrams(self, strs):
dic = {}
strs.sort()
for i in strs:
ii = ''.join(sorted(i))
dic[ii] = dic.get(ii, []) + [i]
'''
if ii in keys:
dic[ii].append(i)
else:
keys.append(ii)
dic[ii] = [i]
'''
res = list(dic.values())
return res
2582



被折叠的 条评论
为什么被折叠?



