113 ms python fast, simple,with hash solution


  • -1
    Z

    class Solution:
    # @param strs, a list of strings
    # @return a list of strings
    def anagrams(self, strs):
    d={}
    res=[]

        l=[]
        
        for s in strs:
            ss=''.join(sorted(s))
            if ss in d:
                    temp=d[ss]
                    temp.append(s)
                    d[ss]=temp
            else:
                    d[ss]=[s]
                   
        for x in d.values():
            if len(x)>2 or len(x)==2:
                res=res+x
        return res

  • 0
    H

    this code is not complete and can be improved.


Log in to reply
 

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