Sorting Python solution, beats 100%


  • 3
    C

    Nothing fancy, just a straightforward solution using a dictionary.

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

  • 0
    Z

    a nice and clean solution


Log in to reply
 

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