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)/统计满足 K 约束的子字符串数量 I [count-substrings-that-satisfy-k-constraint-i].html
2024-08-27 23:06:51 +08:00

59 lines
2.0 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>给你一个 <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>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 50</code></li>
<li><code>1 &lt;= k &lt;= s.length</code></li>
<li><code>s[i]</code><code>'0'</code><code>'1'</code></li>
</ul>