package leetcode;

/**
 * https://leetcode.com/problems/count-binary-substrings/
 */
public class Problem696 {
    public int countBinarySubstrings(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem696 prob = new Problem696();
        System.out.println(prob.countBinarySubstrings("00110011")); // 6
        System.out.println(prob.countBinarySubstrings("10101")); // 4
        System.out.println(prob.countBinarySubstrings("0011")); // 2
        System.out.println(prob.countBinarySubstrings("000111")); // 3
    }
}

@@ -12,16 +12,68 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -217,83 +217,206 @@
     
-// TODO%0A        return 0;%0A
+List%3CCharCount%3E list = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A 
     
-%7D%0A%0A
+ 
     
-public static void main(String%5B%5D args)
+  if (list.isEmpty()) %7B%0A                list.add(new CharCount(s.charAt(i), 1));%0A            %7D else
  %7B%0A 
@@ -426,326 +426,672 @@
     
+  
-Problem696 prob = new Problem696();%0A        System.out.println(prob.countBinarySubstrings(%2200110011%22)); // 6%0A        System.out.println(prob.countBinarySubstrings(%2210101%22)); // 4%0A        System.out.println(prob.countBinarySubstrings(%220011%22)); // 2%0A        System.out.println(prob.countBinarySubstrings(%22000111%22)); // 3
+      CharCount cc = list.get(list.size() - 1);%0A                if (cc.ch == s.charAt(i)) %7B%0A                    cc.count++;%0A                %7D else %7B%0A                    list.add(new CharCount(s.charAt(i), 1));%0A                %7D%0A            %7D%0A        %7D%0A        int result = 0;%0A        for (int i = 0, j = 1; j %3C list.size(); i++, j++) %7B%0A            result += Math.min(list.get(i).count, list.get(j).count);%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static final class CharCount %7B%0A        private final char ch;%0A        private int count;%0A%0A        public CharCount(char ch, int count) %7B%0A            this.ch = ch;%0A            this.count = count;%0A        %7D
 %0A   

Solve problem 696