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 都至少相隔 k 个元素 [check-if-all-1s-are-at-least-length-k-places-away].html
2022-03-29 12:43:11 +08:00

42 lines
1.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>0</code><code>1</code> 组成的数组 <code>nums</code> 以及整数 <code>k</code>。如果所有 <code>1</code> 都至少相隔 <code>k</code> 个元素,则返回 <code>True</code> ;否则,返回 <code>False</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/05/03/sample_1_1791.png" style="width: 214px;"></strong></p>
<pre><strong>输入:</strong>nums = [1,0,0,0,1,0,0,1], k = 2
<strong>输出:</strong>true
<strong>解释:</strong>每个 1 都至少相隔 2 个元素。</pre>
<p><strong>示例 2</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/05/03/sample_2_1791.png" style="height: 86px; width: 160px;"></strong></p>
<pre><strong>输入:</strong>nums = [1,0,0,1,0,1], k = 2
<strong>输出:</strong>false
<strong>解释:</strong>第二个 1 和第三个 1 之间只隔了 1 个元素。</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>nums = [1,1,1,1,1], k = 0
<strong>输出:</strong>true
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>nums = [0,1,0,1], k = 1
<strong>输出:</strong>true
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10^5</code></li>
<li><code>0 &lt;= k &lt;= nums.length</code></li>
<li><code>nums[i]</code> 的值为 <code>0</code><code>1</code></li>
</ul>