Straightforward Python solution with map


  • 0
    Y
    class Solution(object):
        def groupAnagrams(self, strs):
            """
            :type strs: List[str]
            :rtype: List[List[str]]
            """
            strs_list = map(lambda x: ''.join(sorted(list(x))), strs)
            # print strs_list
            d = {}
            for i in range(len(strs_list)):
                if strs_list[i] in d:
                    d[strs_list[i]].append(strs[i])
                else:
                    d[strs_list[i]] = [strs[i]]
            return d.values()
    

Log in to reply
 

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