Very short Python solution


  • 0
    C
    from collections import defaultdict
    class Solution(object):
        def groupAnagrams(self, strs):
            """
            :type strs: List[str]
            :rtype: List[List[str]]
            """
            anagrams = defaultdict(list)
            for str_ in strs:
                anagrams[tuple(sorted(str_))].append(str_)
            return anagrams.values()
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.