package leetcode;

/**
 * https://leetcode.com/problems/bulb-switcher-iv/
 */
public class Problem1529 {
    public int minFlips(String target) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1529 prob = new Problem1529();
        System.out.println(prob.minFlips("10111")); // 3
        System.out.println(prob.minFlips("101")); // 3
        System.out.println(prob.minFlips("00000")); // 0
        System.out.println(prob.minFlips("001011101")); // 5
        System.out.println(prob.minFlips("100100")); // 4
        System.out.println(prob.minFlips("100100")); // 4
        System.out.println(prob.minFlips("100111")); // 3
    }
}

@@ -151,535 +151,452 @@
     
-// TODO%0A        return 0
+int i = target.length() - 1
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1529 prob
+boolean one = target.charAt(target.length() - 1) == '1';%0A        int answer
  = 
+o
 ne
-w Problem1529();%0A        System.out.println(prob.minFlips(%2210111%22)); // 3%0A        System.out.println(prob.minFlips(%22101%22)); // 3%0A        System.out.println(prob.minFlips(%2200000%22)); // 0%0A        System.out.println(prob.minFlips(%22001011101%22)); // 5%0A        System.out.println(prob.minFlips(%22100100%22)); // 4%0A        System.out.println(prob.minFlips(%22100100%22)); // 4%0A        System.out.println(prob.minFlips(%22100111%22)); // 3
+ ? -1 : 0;%0A        while (i %3E= 0) %7B%0A            if (one) %7B%0A                answer += 2;%0A            %7D%0A            while (i %3E= 0 && target.charAt(i) == (one ? '1' : '0')) %7B%0A                i--;%0A            %7D%0A            if (i %3E= 0) %7B%0A                one = target.charAt(i) == '1';%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1529