mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
59 lines
2.0 KiB
HTML
59 lines
2.0 KiB
HTML
<p>给你一个 <strong>二进制</strong> 字符串 <code>s</code> 和一个整数 <code>k</code>。</p>
|
||
|
||
<p>如果一个 <strong>二进制字符串</strong> 满足以下任一条件,则认为该字符串满足 <strong>k 约束</strong>:</p>
|
||
|
||
<ul>
|
||
<li>字符串中 <code>0</code> 的数量最多为 <code>k</code>。</li>
|
||
<li>字符串中 <code>1</code> 的数量最多为 <code>k</code>。</li>
|
||
</ul>
|
||
|
||
<p>返回一个整数,表示 <code>s</code> 的所有满足 <strong>k 约束 </strong>的<span data-keyword="substring-nonempty">子字符串</span>的数量。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong><span class="example-io">s = "10101", k = 1</span></p>
|
||
|
||
<p><strong>输出:</strong><span class="example-io">12</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><code>s</code> 的所有子字符串中,除了 <code>"1010"</code>、<code>"10101"</code> 和 <code>"0101"</code> 外,其余子字符串都满足 k 约束。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong><span class="example-io">s = "1010101", k = 2</span></p>
|
||
|
||
<p><strong>输出:</strong><span class="example-io">25</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><code>s</code> 的所有子字符串中,除了长度大于 5 的子字符串外,其余子字符串都满足 k 约束。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 3:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong><span class="example-io">s = "11111", k = 1</span></p>
|
||
|
||
<p><strong>输出:</strong><span class="example-io">15</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><code>s</code> 的所有子字符串都满足 k 约束。</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= s.length <= 50</code></li>
|
||
<li><code>1 <= k <= s.length</code></li>
|
||
<li><code>s[i]</code> 是 <code>'0'</code> 或 <code>'1'</code>。</li>
|
||
</ul>
|