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 显著的字符串的数量 [count-the-number-of-substrings-with-dominant-ones].html
2024-08-06 08:46:50 +08:00

141 lines
2.5 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></p>
<p>请你统计并返回其中 <strong>1 显著 </strong><span data-keyword="substring-nonempty">子字符串</span> 的数量。</p>
<p>如果字符串中 1 的数量 <strong>大于或等于</strong> 0 的数量的 <strong>平方</strong>,则认为该字符串是一个 <strong>1 显著</strong> 的字符串 。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "00011"</span></p>
<p><strong>输出:</strong><span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<p>1 显著的子字符串如下表所示。</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>0 的数量</th>
<th>1 的数量</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>3</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>01</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>11</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td>011</td>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "101101"</span></p>
<p><strong>输出:</strong><span class="example-io">16</span></p>
<p><strong>解释:</strong></p>
<p>1 不显著的子字符串如下表所示。</p>
<p>总共有 21 个子字符串,其中 5 个是 1 不显著字符串,因此有 16 个 1 显著子字符串。</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>0 的数量</th>
<th>1 的数量</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>1</td>
<td>4</td>
<td>0110</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>0</td>
<td>4</td>
<td>10110</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>5</td>
<td>01101</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 4 * 10<sup>4</sup></code></li>
<li><code>s</code> 仅包含字符 <code>'0'</code><code>'1'</code></li>
</ul>