Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 1513. Number of Substrings With Only 1s
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public:
static const int M = 1000000007;

int numSub(string s) {
long long ans = 0;
long long count1 = 0;

for (char ch : s) {
if (ch == '1') {
count1++;
ans = (ans + count1) % M;
} else {
count1 = 0;
}
}

return (int)ans;
}
};
Loading