Practice Count Binary Substrings
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given 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.
Source: Count Binary Substrings on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
s = "00110011"
Output
6
# Example 2
Input
s = "10101"
Output
4
Constraints
1 <= s.length <= 10^5
s[i] is either '0' or '1'.
Related LeetCode Problems
Practice more problems similar to Count Binary Substrings.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.