926. Flip String to Monotone Increasing
solution
class Solution:
def minFlipsMonoIncr(self, s: str) -> int:
dp = 0
count1 = 0
for c in s:
if c == '0':
# 1. Flip '0'.
# 2. Keep '0' and flip all the previous 1s.
dp = min(dp + 1, count1)
else:
count1 += 1
return dpfollow up
Last updated