package leetcode;

/**
 * https://leetcode.com/problems/maximum-score-after-splitting-a-string/
 */
public class Problem1422 {
    public int maxScore(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1422 prob = new Problem1422();
        System.out.println(prob.maxScore("011101")); // 5
        System.out.println(prob.maxScore("00111")); // 5
        System.out.println(prob.maxScore("1111")); // 3
    }
}

@@ -168,302 +168,606 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1422 prob = new Problem1422();%0A        System.out.println(prob.maxScore(%22011101%22)); // 5%0A        System.out.println(prob.maxScore(%2200111%22)); // 5%0A        System.out.println(prob.maxScore(%221111%22)); // 3
+int ones = 0;%0A        for (char c : s.toCharArray()) %7B%0A            if (c == '1') %7B%0A                ones++;%0A            %7D%0A        %7D%0A        int answer = 0;%0A        int left = 0;%0A        int right = 0;%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            if (s.charAt(i) == '0' && i == s.length() - 1) %7B%0A                continue;%0A            %7D%0A            if (s.charAt(i) == '0') %7B%0A                left++;%0A            %7D else if (s.charAt(i) == '1') %7B%0A                right++;%0A            %7D%0A            answer = Math.max(answer, Math.abs(left + (ones - right)));%0A        %7D%0A        return answer;
 %0A   

Solve problem 1422