package leetcode;

/**
 * https://leetcode.com/problems/flip-string-to-monotone-increasing/
 */
public class Problem926 {
    public int minFlipsMonoIncr(String S) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem926 prob = new Problem926();
        System.out.println(prob.minFlipsMonoIncr("00110")); // 1
        System.out.println(prob.minFlipsMonoIncr("010110")); // 2
        System.out.println(prob.minFlipsMonoIncr("00011000")); // 2
        System.out.println(prob.minFlipsMonoIncr("0100111")); // 1
        System.out.println(prob.minFlipsMonoIncr("100100111")); // 2
        System.out.println(prob.minFlipsMonoIncr("1001001110")); // 3
        System.out.println(prob.minFlipsMonoIncr("00001")); // 0
        System.out.println(prob.minFlipsMonoIncr("11110")); // 1
        System.out.println(prob.minFlipsMonoIncr("11100")); // 2
    }
}

@@ -171,729 +171,506 @@
     
-// TODO%0A        return 0
+int%5B%5D sum = new int%5BS.length() + 1%5D
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem926 prob = new Problem926();%0A        System.out.println(prob.minFlipsMonoIncr(%2200110%22)); // 1%0A        System.out.println(prob.minFlipsMonoIncr(%22010110%22)); // 2%0A        System.out.println(prob.minFlipsMonoIncr(%2200011000%22)); // 2%0A        System.out.println(prob.minFlipsMonoIncr(%220100111%22)); // 1%0A        System.out.println(prob.minFlipsMonoIncr(%22100100111%22)); // 2%0A        System.out.println(prob.minFlipsMonoIncr(%221001001110%22)); // 3%0A        System.out.println(prob.minFlipsMonoIncr(%2200001%22)); // 0%0A        System.out.println(prob.minFlipsMonoIncr(%2211110%22)); // 1%0A        System.out.println(prob.minFlipsMonoIncr(%2211100%22)); // 2
+for (int i = 0; i %3C S.length(); ++i) %7B%0A            sum%5Bi + 1%5D = sum%5Bi%5D + (S.charAt(i) == '1' ? 1 : 0);%0A        %7D%0A        int min = Integer.MAX_VALUE;%0A        for (int i = 0; i %3C= S.length(); ++i) %7B%0A            // Number of ones to flip.%0A            int left = sum%5Bi%5D;%0A            // Number of zeros to flip.%0A            int right = S.length() - i - (sum%5BS.length()%5D - sum%5Bi%5D);%0A            min = Math.min(min, left + right);%0A        %7D%0A        return min;
 %0A   

Solve problem 926