全零子串的数量
全零子串的数量
题目:全零子串的数量
给出一个只包含0
或1
的字符串str
,请返回这个字符串中全为0
的子字符串的个数
1<=|str|<=30000
示例:
输入:"00010011"
输出:9
解释:
"0"子字符串有5个,
"00"子字符串有3个,
"000"子字符串有1个。
所以返回9
代码:
public class Solution {
/**
* @param str: the string
* @return: the number of substrings
*/
public int stringCount(String str) {
int l = str.length(),sum, res=0,j;
for(int i=0; i