Time Limit Exceeded Error. Why is this code not efficient ?


  • 0

    class Solution(object):

       def findAnagrams(self, s, p):
            if len(s)<len(p): return []
            if len(s)==0:return []
            a=len(s)-len(p)
            l1=[]
            for i in range(0,a+1):
                if sorted(p)==sorted(s[i:i+len(p)]):
                    l1.append(i)
            return l1

Log in to reply
 

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