Python solution using dictionary as hashtable - beats 58%


  • 0
    O
    def groupAnagrams(self, strs):
    
        res = collections.defaultdict(list)
        for s in strs:
            res["".join(sorted(s))].append(s)
        
        return map(lambda k: sorted(res[k]), res.keys())
    

    Let me know if you have any faster approach. Always fun to improve :-)


  • 0
    J

    Hi!

    return map(lambda v: sorted(v), result_map.values())
    

    Just a little improvement and beats 73%.


Log in to reply
 

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