share my python solution


  • 0
    W

    class Solution(object):
    def groupAnagrams(self, strs):
    """
    :type strs: List[str]
    :rtype: List[List[str]]
    """

        myMap = {}
        for string in strs :
            myKey = ''.join(sorted(list(string)))
            
            try : 
                myArray = myMap[myKey]
                myArray.append(string)
            except:
                myArray = []
                myArray.append(string)
                myMap[myKey] = myArray
            
    
        return myMap.values()

Log in to reply
 

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