mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
251116
This commit is contained in:
20
25/11/1513.cpp
Normal file
20
25/11/1513.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user