public class Solution {
public bool CanPlaceFlowers(int[] flowerbed, int n) {
if (flowerbed.Length == && flowerbed[] == )
{
n = n - ;
if (n <= )
{
return true;
}
else
{
return false;
}
} var conti = ;
var firstOne = false;
for (int i = ; i < flowerbed.Length; i++)
{
if (flowerbed[i] == )
{
conti++;
}
else
{
if (firstOne)
{
if (conti <= )
{
conti = ;
}
else
{
if (conti % == )
{
n = n - (conti / - );
}
else
{
n = n - ((conti + ) / - );
}
if (n <= )
{
return true;
}
conti = ;
}
}
else
{
if (conti <= )
{
conti = ;
}
else
{
n = n - (conti / );
if (n <= )
{
return true;
}
conti = ;
}
}
firstOne = true;
}
}
if (conti <= )
{
conti = ;
}
else
{
if (firstOne)
{
n = n - (conti / );
}
else
{
n = n - (conti + ) / ;
}
}
if (n <= )
{
return true;
}
else
{
return false;
}
}
}

https://leetcode.com/problems/can-place-flowers/#/description

leetcode605的更多相关文章

  1. [Swift]LeetCode605. 种花问题 | Can Place Flowers

    Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, ...

  2. Leetcode605.Can Place Flowers种花问题

    假设你有一个很长的花坛,一部分地块种植了花,另一部分却没有.可是,花卉不能种植在相邻的地块上,它们会争夺水源,两者都会死去. 给定一个花坛(表示为一个数组包含0和1,其中0表示没种植花,1表示种植了花 ...

随机推荐

  1. WCF基础:绑定(二)

    在WCF的绑定体系中,经常会碰到ICommunicationObject接口,无论是IChannel接口还是IChannelListener/IChannelFactory接口都继承了ICommuni ...

  2. LeetCode OJ:Plus One (加1)

    Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...

  3. UI- 基础控件零散知识点回归

    1.frame\center\bounds 1> frame:能修改位置和尺寸 2> center:能修改位置 3> bounds:能修改尺寸(x\y一般都是0) 2.在.m中声明的 ...

  4. C# 为什么用接口实例化一个实现该接口的类?

    这是多态的体现. 首先接口不能实例化的. 实现接口的类 实例 = new 实现接口的类()// 这样用不好吗? //这样已经不是好不好的问题了,这样的话,要接口有什么用?//用接口就是让实例和实现类的 ...

  5. Git常用命令以及用法

    一 如何让单个文件回退到指定的版本 1.   进入到文件所在文件目录,或者能找到文件的路径 查看整个目录的修改记录 git log . 2.   回退到指定的版本 git reset f7a22076 ...

  6. [置顶] Git 配置SSH简单玩法?

    > 第一步下载git点击直接下载 他会检测您的系统当前是64bit还是32bit安装过程不再啰嗦反正就是Next Next Next Finish 第二步这里你可以下载TortoiseGit点击 ...

  7. 一次不成功的脚本Hack[捕鱼达人游戏]

    捕鱼达人这款游戏[http://keleyi.com/game/1/] 想当然的以为在这个id为“fishContainer”的div上绑定一个点击事件,子弹就可以快速的发射. 为此用油猴挂载了一个j ...

  8. 网络爬虫必备知识之urllib库

    就库的范围,个人认为网络爬虫必备库知识包括urllib.requests.re.BeautifulSoup.concurrent.futures,接下来将结合爬虫示例分别对urllib库的使用方法进行 ...

  9. 51nod 1085 背包问题

    在N件物品取出若干件放在容量为W的背包里,每件物品的体积为W1,W2……Wn(Wi为整数),与之相对应的价值为P1,P2……Pn(Pi为整数).求背包能够容纳的最大价值. 收起   输入 第1行,2个 ...

  10. webstorm-前端javascript开发神器中文教程和技巧分享(转)

    webstorm是一款前端javascript开发编辑的神器,此文介绍webstorm的中文教程和技巧分享. webstorm8.0.3中文汉化版下载:百度网盘下载:http://pan.baidu. ...