def maxone(self, A, B):
start = 0
end = 0
count = 0
mid = -1
maxlen = -1
maxstart = -1
maxend = -1
if B == 0:
while end < len(A):
if A[end] == 0:
if count != 0 and maxlen < count:
maxlen = count
maxstart = end-count
maxend = end-1
count = 0
else:
count += 1
end += 1
if count > 0 and maxlen < count:
maxstart = end-count
maxend = end-1
maxlen = count
if maxlen == -1:
return []
return range(maxstart,maxend+1)
while start < len(A):
if end == len(A):
if count == 0:
maxstart = 0
maxend = len(A)-1
else:
if maxlen < end-start:
maxstart = start
maxend = end-1
break
if A[end] == 0:
count += 1
if count == 1:
mid = end + 1
if count > B:
if maxlen < end-start:
maxstart = start
maxend = end-1
maxlen = end-start
start = mid
end = start
count = 0
continue
end += 1
return range(maxstart,maxend+1)
A = array of numbers with 0 and 1s
B = count of 0's can be flipped
B = count of 0's can be flipped
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.