标签:python ted class app sel ams elf self obj
mycode 95.35%
思路:构建字典
class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype: List[List[str]] """ dic = {} for item in strs: temp = ‘‘.join(sorted(item)) if temp not in dic: dic[temp] = [item] else: dic[temp].append(item) return list(dic.values())
下面是list的加法
if temp not in dic:
dic[temp] = [item]
else:
dic[temp] += [item]
if temp not in dic: dic[temp] = [item] else: dic[temp] += [item]
leetcode-mid-array-49 Group Anagrams
标签:python ted class app sel ams elf self obj
原文地址:https://www.cnblogs.com/rosyYY/p/10963942.html