package leetcode;

/**
 * https://leetcode.com/problems/maximum-binary-string-after-change/
 */
public class Problem1702 {
    public String maximumBinaryString(String binary) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1702 prob = new Problem1702();
        System.out.println(prob.maximumBinaryString("000110")); // "111011"
        System.out.println(prob.maximumBinaryString("0000110")); // "1111011"
        System.out.println(prob.maximumBinaryString("01")); // "01"
        System.out.println(prob.maximumBinaryString("100011001010101001")); // "111111111101111111"
        System.out.println(prob.maximumBinaryString("000011001010101001")); // "111111111101111111"
        System.out.println(prob.maximumBinaryString("1000011001010101001")); // "1111111111101111111"
        System.out.println(prob.maximumBinaryString("1000111100101011101")); // "1111111101111111111"
        System.out.println(prob.maximumBinaryString("0100111100101011101")); // "1111111011111111111"
        System.out.println(prob.maximumBinaryString("0010111100101011101")); // "1111111011111111111"
        System.out.println(prob.maximumBinaryString("01010101010101")); // 11111101111111
        System.out.println(prob.maximumBinaryString("0101")); // "1011"
        System.out.println(prob.maximumBinaryString("1010")); // "1101"
        System.out.println(prob.maximumBinaryString("1111")); // "1111"
        System.out.println(prob.maximumBinaryString("0000")); // "1110"
        System.out.println(prob.maximumBinaryString("00010101")); // "11110111"
        System.out.println(prob.maximumBinaryString("0100000101")); // "1111110111"
        System.out.println(prob.maximumBinaryString("0000000101")); // "1111111011"
        System.out.println(prob.maximumBinaryString("1000000101")); // "1111111011"
        System.out.println(prob.maximumBinaryString("1111000101")); // "1111111011"
        System.out.println(prob.maximumBinaryString("1011000101")); // "1111101111"
    }
}


@@ -183,1842 +183,540 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1702 prob = new Problem1702();%0A        System.out.println(prob.maximumBinaryString(%22000110%22)); // %22111011%22%0A        System.out.println(prob.maximumBinaryString(%220000110%22)); // %221111011%22%0A        System.out.println(prob.maximumBinaryString(%2201%22)); // %2201%22%0A        System.out.println(prob.maximumBinaryString(%22100011001010101001%22)); // %22111111111101111111%22%0A        System.out.println(prob.maximumBinaryString(%22000011001010101001%22)); // %22111111111101111111%22%0A        System.out.println(prob.maximumBinaryString(%221000011001010101001%22)); // %221111111111101111111%22%0A        System.out.println(prob.maximumBinaryString(%221000111100101011101%22)); // %221111111101111111111%22%0A        System.out.println(prob.maximumBinaryString(%220100111100101011101%22)); // %221111111011111111111%22%0A        System.out.println(prob.maximumBinaryString(%220010111100101011101%22)); // %221111111011111111111%22%0A        System.out.println(prob.maximumBinaryString(%2201010101010101%22)); // 11111101111111%0A        System.out.println(prob.maximumBinaryString(%220101%22)); // %221011%22%0A        System.out.println(prob.maximumBinaryString(%221010%22)); // %221101%22%0A        System.out.println(prob.maximumBinaryString(%221111%22)); // %221111%22%0A        System.out.println(prob.maximumBinaryString(%220000%22)); // %221110%22%0A        System.out.println(prob.maximumBinaryString(%2200010101%22)); // %2211110111%22%0A        System.out.println(prob.maximumBinaryString(%220100000101%22)); // %221111110111%22%0A        System.out.println(prob.maximumBinaryString(%220000000101%22)); // %221111111011%22%0A        System.out.println(prob.maximumBinaryString(%221000000101%22)); // %221111111011%22%0A        System.out.println(prob.maximumBinaryString(%221111000101%22)); // %221111111011%22%0A        System.out.println(prob.maximumBinaryString(%221011000101%22)); // %221111101111%22
+StringBuilder answer = new StringBuilder(%221%22.repeat(binary.length()));%0A        int zeroCount = 0;%0A        int oneCount = 0;%0A        int i = 0;%0A        for (; i %3C binary.length() && binary.charAt(i) == '1'; i++) %7B%0A            oneCount++;%0A        %7D%0A        for (; i %3C binary.length(); i++) %7B%0A            if (binary.charAt(i) == '0') %7B%0A                zeroCount++;%0A            %7D%0A        %7D%0A        if (oneCount %3C binary.length()) %7B%0A            answer.setCharAt(zeroCount + oneCount - 1, '0');%0A        %7D%0A        return answer.toString();
 %0A   

Solve problem 1702