Flip String to Monotone Increasing
Previous843. Guess the WordNext1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance
Last updated
Last updated
class Solution {
public:
int minFlipsMonoIncr(string S) {
int flips = 0, ones = 0;
for (int i = 0; i < S.size(); ++i) {
if (S[i] == '0') {
if (ones == 0) continue;
++flips;
} else {
++ones;
}
if (flips > ones) flips = ones;
}
return flips;
}
};