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)/种花问题 [can-place-flowers].html

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