5-line easy understand python solution


  • 0

    It's vey straight forward, but it's not the best solution.

    def groupAnagrams(self, strs):
            """
            :type strs: List[str]
            :rtype: List[List[str]]
            """
            hashmap={}
            for i in xrange(len(strs)):
                # sorted the key 
                key=''.join(sorted(strs[i]))
                # if the key is the same plus
                hashmap[key]=hashmap.get(key,[])+[strs[i]]
            return [v for v in hashmap.values()]
    

Log in to reply
 

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