605. Can Place Flowers
题目:
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.
Given a flowerbed (represented as an array containing 0 and 1, where 0 means empty and 1 means not empty), and a number n, return if n new flowers can be planted in it without violating the no-adjacent-flowers rule.
Example 1:
Input: flowerbed = [1,0,0,0,1], n = 1 Output: True
Example 2:
Input: flowerbed = [1,0,0,0,1], n = 2 Output: False
Note:
思路:
本题,只要就算可以插花的个数,每连续三个0可以插一朵花,但是要注意首尾为0的特殊情况
代码:
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
int i = 0;
while(i<flowerbed.size())
{
if(flowerbed[i]==0&&(i==0||flowerbed[i-1]==0)&&(i==flowerbed.size()-1||flowerbed[i+1]==0))
{
n--;
flowerbed[i] = 1;
}
i++;
}
return n<1?true:false;
}
};
相关知识
将会种植更多的鲜花来美化城市 的翻译是:More flowers will be planted to beautify the city 中文翻译英文意思,翻译英语
雅思口语Part 1答题模板:花鸟鱼虫
flowers的意思
你可以足不出户订购全球任一国家任意地区的鲜花、牛奶、餐点等,并直接送货上门; 的翻译是:You can be ordered without having any country any region in the world, such as flowers, milk, food, and deliver it directly; 中文翻译英文意思,翻译英语
问展丨2019深圳花展——容器花园展、创意花园展、花艺展
Leetcode刷题笔记 605. 种花问题
治愈全网!小伙用羊毛毡“小花”修补城市街角,网友:好温暖的补丁……
Realize one's ambition
children can explore the plants' need for water by growing flowers and vegetables and watering them with eyedroppers, 的翻译是:儿童可以由种植鲜花和蔬菜和浇水使用吸管工具,探索植物对水的需求 中文翻译英文意思,翻译英语
新浪教育
原文链接: 605. Can Place Flowers https://www.huajiangbk.com/newsview212257.html
| 上一篇: 牡丹广场东西花坛的绿化考虑升级一... | 下一篇: 《星际锦鲤养包子》 |
推荐分享

- 1明日花キララ:明日花绮罗年度... 29029
- 2明日花キララ(明日花绮罗)经... 16854
- 3五月天婷婷开心六月丁香:音乐... 11067
- 4家庭养花知识大全 家庭养花有... 10661
- 5家庭养花风水知识 家庭养花“... 10339
- 6兰花叶子扭的是什么兰 9016
- 7秋天养花,掌握这5点养花知识... 8757
- 8十大致癌花卉排行榜,哪些花卉... 8717
- 9君子兰什么品种最名贵 十大名... 8618
- 10【花卉知识 】养花须知:新手... 8357




