Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 426 Bytes

049.md

File metadata and controls

20 lines (18 loc) · 426 Bytes

49. Group Anagrams

Solution 1

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