# Leetcode 696 - Count Binary Substrings

Note:

• Is this really an easy problem?
• Imagine all consecutive 0 and 1 will form an array like 2,1,3,4,5... in which each num is the count of consecutive 1 or 0.
• Min(m, n) for every adjacent pair is how many grouped 1 & 0 pairs we can derive from a pair.
• For example, 1100011 lead to 2,3,2
• 1100 gives us 1100,and 10, which is min(2,3) = 2;
• 00011 give us 0011, 01, which is min(3,2) = 2;

Question:

Give a binary string s, return the number of non-empty substrings that have the same number of 0‘s and 1‘s, and all the 0’s and all the 1’s in these substrings are grouped consecutively.

Substrings that occur multiple times are counted the number of times they occur.

Example:

Code: