代码拉取完成,页面将自动刷新
<p>You are given a binary string <code>s</code>.</p>
<p>Return the number of <span data-keyword="substring-nonempty">substrings</span> with <strong>dominant</strong> ones.</p>
<p>A string has <strong>dominant</strong> ones if the number of ones in the string is <strong>greater than or equal to</strong> the <strong>square</strong> of the number of zeros in the string.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = "00011"</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>The substrings with dominant ones are shown in the table below.</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>Number of Zeros</th>
<th>Number of Ones</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">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = "101101"</span></p>
<p><strong>Output:</strong> <span class="example-io">16</span></p>
<p><strong>Explanation:</strong></p>
<p>The substrings with <strong>non-dominant</strong> ones are shown in the table below.</p>
<p>Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.</p>
</div>
<table>
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>s[i..j]</th>
<th>Number of Zeros</th>
<th>Number of Ones</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> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 4 * 10<sup>4</sup></code></li>
<li><code>s</code> consists only of characters <code>'0'</code> and <code>'1'</code>.</li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。