Skip to content

Commit 7e5c715

Browse files
authored
Create 1513. Number of Substrings With Only 1s (#934)
2 parents 6f61d3c + 7708267 commit 7e5c715

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
static const int M = 1000000007;
4+
5+
int numSub(string s) {
6+
long long ans = 0;
7+
long long count1 = 0;
8+
9+
for (char ch : s) {
10+
if (ch == '1') {
11+
count1++;
12+
ans = (ans + count1) % M;
13+
} else {
14+
count1 = 0;
15+
}
16+
}
17+
18+
return (int)ans;
19+
}
20+
};

0 commit comments

Comments
 (0)