diff --git a/1513. Number of Substrings With Only 1s b/1513. Number of Substrings With Only 1s new file mode 100644 index 0000000..daaa708 --- /dev/null +++ b/1513. Number of Substrings With Only 1s @@ -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; + } +};