1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/种花问题 [can-place-flowers].html
2022-03-29 12:43:11 +08:00

31 lines
1.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>假设有一个很长的花坛,一部分地块种植了花,另一部分却没有。可是,花不能种植在相邻的地块上,它们会争夺水源,两者都会死去。</p>
<p>给你一个整数数组  <code>flowerbed</code> 表示花坛,由若干 <code>0</code><code>1</code> 组成,其中 <code>0</code> 表示没种植花,<code>1</code> 表示种植了花。另有一个数 <code>n</code><strong> </strong>,能否在不打破种植规则的情况下种入 <code>n</code><strong> </strong>朵花?能则返回 <code>true</code> ,不能则返回 <code>false</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>flowerbed = [1,0,0,0,1], n = 1
<strong>输出:</strong>true
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>flowerbed = [1,0,0,0,1], n = 2
<strong>输出:</strong>false
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= flowerbed.length <= 2 * 10<sup>4</sup></code></li>
<li><code>flowerbed[i]</code><code>0</code><code>1</code></li>
<li><code>flowerbed</code> 中不存在相邻的两朵花</li>
<li><code>0 <= n <= flowerbed.length</code></li>
</ul>