Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 500 Bytes

049._group_anagrams_python.md

File metadata and controls

28 lines (21 loc) · 500 Bytes

49. Group Anagrams python

题目: https://leetcode.com/problems/anagrams/

难度 : Medium

python大法好

class Solution(object):
    def groupAnagrams(self, strs):
        """
        :type strs: List[str]
        :rtype: List[List[str]]
        """
        mapx = {}
        for i in strs:
            x = ''.join(sorted(list(i)))
            if x in mapx:
                mapx[x].append(i)
            else:
                mapx[x] = [i]
        return mapx.values()