Description
Given a binary string s, return the number of non-empty substrings that have the same number of 0s and 1s, and all the 0s and 1s are grouped consecutively.
Examples
Input:
s = "00110011"Output:
6Explanation:
0011,01,1100,10,0011,01.
Input:
s = "000111"Output:
3Explanation:
There are 3 valid substrings: "01" (at positions 2-3), "0011" (at positions 1-4), and "000111" (the entire string). Each substring has equal consecutive 0s and 1s - one group of 0s followed by one group of 1s of the same length.
Input:
s = "1001"Output:
2Explanation:
There are 2 valid substrings: "10" (at positions 0-1) and "01" (at positions 2-3). The substring "1001" is not valid because it has two separate groups of 1s, which violates the requirement of having consecutive equal groups.
Constraints
- •
1 ≤ s.length ≤ 10⁵