1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/仅含 1 的子串数 [number-of-substrings-with-only-1s].html
2022-03-29 12:43:11 +08:00

46 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个二进制字符串 <code>s</code>(仅由 &#39;0&#39;&#39;1&#39; 组成的字符串)。</p>
<p>返回所有字符都为 1 的子字符串的数目。</p>
<p>由于答案可能很大,请你将它对 10^9 + 7 取模后返回。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = &quot;0110111&quot;
<strong>输出</strong>9
<strong>解释:</strong>共有 9 个子字符串仅由 &#39;1&#39; 组成
&quot;1&quot; -&gt; 5 次
&quot;11&quot; -&gt; 3 次
&quot;111&quot; -&gt; 1 次</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = &quot;101&quot;
<strong>输出:</strong>2
<strong>解释:</strong>子字符串 &quot;1&quot; 在 s 中共出现 2 次
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s = &quot;111111&quot;
<strong>输出:</strong>21
<strong>解释:</strong>每个子字符串都仅由 &#39;1&#39; 组成
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>s = &quot;000&quot;
<strong>输出:</strong>0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>s[i] == &#39;0&#39;</code><code>s[i] == &#39;1&#39;</code></li>
<li><code>1 &lt;= s.length &lt;= 10^5</code></li>
</ul>