java.lang.Object
g1501_1600.s1513_number_of_substrings_with_only_1s.Solution

public class Solution extends Object
1513 - Number of Substrings With Only 1s.<p>Medium</p> <p>Given a binary string <code>s</code>, return <em>the number of substrings with all characters</em> <code>1</code><em>&rsquo;s</em>. Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;0110111&rdquo;</p> <p><strong>Output:</strong> 9</p> <p><strong>Explanation:</strong> There are 9 substring in total with only 1&rsquo;s characters. &ldquo;1&rdquo; -> 5 times. &ldquo;11&rdquo; -> 3 times. &ldquo;111&rdquo; -> 1 time.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;101&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Substring &ldquo;1&rdquo; is shown 2 times in s.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;111111&rdquo;</p> <p><strong>Output:</strong> 21</p> <p><strong>Explanation:</strong> Each substring contains only 1&rsquo;s characters.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numSub

      public int numSub(String s)