<p>Given a binary string <code>s</code>, return <em>the number of substrings with all characters</em> <code>1</code><em>&#39;s</em>. Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;0110111&quot;
<strong>Output:</strong> 9
<strong>Explanation:</strong> There are 9 substring in total with only 1&#39;s characters.
&quot;1&quot; -&gt; 5 times.
&quot;11&quot; -&gt; 3 times.
&quot;111&quot; -&gt; 1 time.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;101&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> Substring &quot;1&quot; is shown 2 times in s.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;111111&quot;
<strong>Output:</strong> 21
<strong>Explanation:</strong> Each substring contains only 1&#39;s characters.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
</ul>

class Solution {
public:
    // Define a constant for modular arithmetic
    const int MOD = 1e9 + 7;

    // Function to count the number of valid substrings in a binary string
    int numSub(string s) {
        // Initialize start and end pointers
        int start = 0, end = 0;

        // Get the length of the input string
        int len = s.length();

        // Variable to store the total number of valid substrings
        int totalSubStrings = 0;

        // Loop through the characters of the string
        while(end < len){
            // If the current character is '0', move the start pointer
            // to the next character and continue to the next iteration
            if(s[end] == '0'){
                end += 1;
                start = end;
                continue;
            }

            // Calculate the number of valid substrings ending at the current position
            totalSubStrings += ((end - start + 1) % MOD);
            totalSubStrings %= MOD;
            
            // Move the end pointer to the next character
            end += 1;
        }

        // Return the total number of valid substrings
        return totalSubStrings;
    }
};
10200