public class Solution {
/**
* @param str: the string
* @return: the number of substrings
00010011
*/
public int stringCount(String str) {
int result = 0;
int n = str.length();
int j = 1;
for (int i = 0; i < n; i++) {
if (str.charAt(i) != '0') {
continue;
}
j = Math.max(j, i+1);
while (j < n && str.charAt(j) == '0') {
j++;
}
result += j - i;
}
return result;
}
}