← 返回 jpmorgan 的题目列表Count Binary Substrings
类型:online_judge
Given a binary string s, return the number of non-empty (contiguous) substrings that satisfy the following criteria: each 0 or 1 in these substrings appears the same number of times. For example, for the string "00110011", the result is 6 because there are six such substrings: “0011”, “01”, “1100”, “10”, “0011”, “01”.
Input Description:
Input is a binary string s of length within the range [1, 50,000].
Output Description:
Output the number of substrings satisfying the criteria.
Example:
Input: "00110011" Output: 6
Input: "10101" Output: 4
Example
Input
00110011