Files
leetcode/25/11/1513.cpp
2025-11-16 21:10:46 +08:00

20 lines
382 B
C++

#include <string>
int numSub(std::string s) {
int count = 0;
long ans = 0;
int mod = 1e9+7;
int n = s.length();
for(int i = 0;i<n;i++){
if(s[i] == '1'){
count++;
}
if(s[i] == '0' || i == n-1){
while (count != 0) {
ans += count--;
}
}
}
return int(ans % mod);
}