Please tell me why my solution having TLE (python3)


#1

class Solution:
# @param A : string
# @return a list of integers
def flip(self, A):
res = []
li = []
for i in range(len(A)):
if A[i] == ‘0’:
li.append(i)

    if len(li) == 0:
        return res
    a = 1
    i = 0
    start = li[0]
    end = li[0]
    count = 0
    l = 0
    k = 0
    max_count = A.count('1')
    max_A = max_count
    while(a == 1):
        if A[end] == '0':
            count += 1
                
        else :
            count -= 1
            
        if max_count < (max_A + count) :
            max_count = max_A + count
            l = start + 1
            k = end + 1
        
        end += 1        
        if count < 0:
            i += 1
            count = 0
            start = li[i]
            end = li[i] 
        
        
        if i == (len(li) - 1) or end == (li[-1] + 1):
            break
    
    if l != 0 and k != 0:
        res.append(l)
        res.append(k)
    return res