[TLE] Should give the code more time when using Python?


  • 0
    L

    I don't know how to improve it. May be I should change my algorithm.

    def anagrams(self, strs):
        sorted_strs = []
        result = []
        
        for s in strs:
            sorted_strs.append(''.join(sorted(list(s))))
        
        for i, s in enumerate(sorted_strs):
            if sorted_strs.count(s) > 1:
                result.append(strs[i])
                    
        return result

Log in to reply
 

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