a simple python solution


  • 0
    N
    class Solution(object):
        def groupAnagrams(self, strs):
            """
            :type strs: List[str]
            :rtype: List[List[str]]
            """
            temp_dict = {}
            for s in strs:
                key = ''.join(sorted(s))
                if temp_dict.has_key(key):
                    temp_dict[key].append(s)
                else:
                    temp_dict[key] = [s]
            
            return temp_dict.values()
    

    if the 'temp_dict.has_key(key)' replace to 'key in temp_dict.keys()', time limit exceeded...


Log in to reply
 

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