python beawts 99%


  • 0
    X
    class Solution(object):
        def groupAnagrams(self, strs):
            """
            :type strs: List[str]
            :rtype: List[List[str]]
            """
            # hashtale {(a, b, c): ["abc", "bca"]}
            # 
            mp = {}
            for s in strs:
                lst = list(s); lst.sort(); lst = tuple(lst)
                if mp.get(lst):
                    mp[lst].append(s)
                else:
                    mp[lst] = [s]
            return mp.values()
    

Log in to reply
 

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