cswork / OA打开练习工作台

JPMorgan ChaseOA #34

Count Equal Binary Substrings

估计简单可在线判题

考点(AI 标注)字符串双指针滑窗

Count the substrings that have the same number of 0s and 1s, with all 0s contiguous and all 1s contiguous; identical text at different positions is counted separately. 0110 has equal counts but does not qualify.

输入格式

The first line contains the length n, and the second line contains the binary string; the original gives no length bound, so this site uses 0≤n≤200000, and an empty string is an empty line.

输出格式

Output a single integer answer.

样例 1

输入:

6
011001

输出:

4

样例 2

输入:

0

输出:

0

样例 3

输入:

4
0011

输出:

2

样例说明

The outputs of the three public examples are, in order: 4; 0; 2. These answers have been checked by independent enumeration or direct simulation.