4 line python solution and beats 95%


  • 0
    P
    class Solution(object):
        def groupAnagrams(self, strs):
            """
            :type strs: List[str]
            :rtype: List[List[str]]
            """
            dd=collections.defaultdict(list)
            for i in strs:
                dd["".join(sorted(i))].append(i)
            return [value for key,value in dd.items()]
    

Log in to reply
 

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