LoginSignup
0
0

More than 1 year has passed since last update.

Leetcode 926. Flip String to Monotone Increasing

Last updated at Posted at 2023-01-17

難易度

Medium

アプローチ

Prefix Sum, Brute-force

class Solution {
    public int minFlipsMonoIncr(String s) {
        int count = 0;
        int result = 0;
        for (char sChar : s.toCharArray()) {
            if (sChar == '1') {
                count++;
            } else if (count > 0 && sChar == '0') {
                count--;
                result++;
            }
        }
        return result;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0