926. Flip String to Monotone Increasing
On This Page
class Solution:
def minFlipsMonoIncr(self, s: str) -> int:
n = len(s)
presum = [0] * (n + 1)
for i, c in enumerate(s):
presum[i + 1] = presum[i] + int(c)
res = presum[-1]
for i in range(n):
res = min(res, presum[i] + n - i - (presum[-1] - presum[i]))
return res