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. Qt中切换窗口功能的实现

    两条语句就能够实现了: this->newNC.setWindowFlags(Qt::WindowStaysOnTopHint); this->newNC.show(); mark一下,防 ...

  2. Android平台下渗透测试工具大集合

    Android平台下渗透测试工具大集合 分享一个google的项目,各种Android下的渗透测试工具. Ad Network Detector (1.2): http://market.androi ...

  3. Ubuntu+Rmarkdown的中文slides实现(附GitHub template)

    这两天要做毕业论文的答辩slides,搜Rmarkdown中文slides的时候百度到了自己两年前的博客 R+markdown+LaTeX 中文编译解决方案.讲真我一开始还真没有认出来,一看这文风和博 ...

  4. 小程序连续点击bug解决

    问题描述: 1)wxml片段 <view bindtap="loadMulti"> <text>连续点击,加载多次</text> </vi ...

  5. Sublime Text 3下Emmet使用技巧

    链接:http://jingyan.baidu.com/article/92255446a87900851648f4d6.html

  6. 1076. Wifi密码 (15)

    下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用wifi,又怕耽误亲们的学习,现将wifi密码设置为下列数学题答案:A-1:B-2:C-3:D-4:请同学们自己作答,每两日一换.谢 ...

  7. AngularJS方法 —— angular.bootstrap

    描述: 此方法用于手动加载angularjs模板 (官方翻译:注意基于端到端的测试不能使用此功能来引导手动加载,他们必须使用ngapp. angularjs会检测这个模板是否被浏览器加载或者加载多次并 ...

  8. 【转载】对一致性Hash算法,Java代码实现的深入研究

    原文地址:http://www.cnblogs.com/xrq730/p/5186728.html 一致性Hash算法 关于一致性Hash算法,在我之前的博文中已经有多次提到了,MemCache超详细 ...

  9. 在idea下两个项目之间的maven父子级项目依赖

    配置:idea 在一个项目中的父子级依赖网上轮子太多,我就不重复造了,留个链接 http://www.cnblogs.com/tibit/p/6185704.html 说说一些我自己注意的问题,在pr ...

  10. spring新心得

    一直觉得spring是最厉害的框架,说说最近从依葫芦画瓢到现在慢慢摸索他的思想的过程 以前什么都不懂,在xml上抄网上的东西,到大概知道是什么运作的 三种配装方式 1,<spring实战> ...