Count Binary Substrings
A binary string is a string consisting only of 0s and 1s. A substring is a contiguous group of characters within a string.
Given a binary string, find the number of substrings that contain an equal number of 0s and 1s and all the 0s and 1s are grouped together. Note that duplicate substrings are also counted in the answer. For example, '0011' has two overlapping substrings that meet the criteria: '0011' and '01'.
Complete the function getSubstringCount in the editor.
getSubstringCount has the following parameter(s):
s: a binary string
Returns
int: the number of substrings that meet the criteria
1Example 1
Constraints
Limits and guarantees your solution can rely on.
- The length of
s≤ 10^5 - The string consists of 0s and 1s only.