LeetCode-49-Group Anagrams list_to_string、string list

来源:互联网 发布:80端口入侵 编辑:程序博客网 时间:2024/06/06 01:48


class Solution(object):    def groupAnagrams(self, strs):        """        :type strs: List[str]        :rtype: List[List[str]]        """        Len=len(strs)        Map={}        count=0        ans=[]        for i in range(Len):            curS=strs[i]            l=list(curS)            l.sort()            curSort="".join(l)            if curSort not in Map:                Map[curSort]=count                ans.append([curS])                count+=1            else:                index=Map[curSort]                ans[index].append(curS)        return ans


原创粉丝点击