mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
30 lines
1.1 KiB
HTML
30 lines
1.1 KiB
HTML
<p>给定一个二进制数组 <code>nums</code> 和一个整数 <code>k</code>,假设最多可以翻转 <code>k</code> 个 <code>0</code> ,则返回执行操作后 <em>数组中连续 <code>1</code> 的最大个数</em> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [1,1,1,0,0,0,1,1,1,1,0], K = 2
|
||
<strong>输出:</strong>6
|
||
<strong>解释:</strong>[1,1,1,0,0,<strong>1</strong>,1,1,1,1,<strong>1</strong>]
|
||
粗体数字从 0 翻转到 1,最长的子数组长度为 6。</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], K = 3
|
||
<strong>输出:</strong>10
|
||
<strong>解释:</strong>[0,0,1,1,<strong>1</strong>,<strong>1</strong>,1,1,1,<strong>1</strong>,1,1,0,0,0,1,1,1,1]
|
||
粗体数字从 0 翻转到 1,最长的子数组长度为 10。</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||
<li><code>nums[i]</code> 不是 <code>0</code> 就是 <code>1</code></li>
|
||
<li><code>0 <= k <= nums.length</code></li>
|
||
</ul>
|