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. Struts02---实现struts2的三种方式

    01.创建普通类 /** * 01.普通类 * 写一个execute() 返回String类型值 * */ public class HelloAction01 { public String exe ...

  2. LeetCode OJ:Best Time to Buy and Sell Stock II(股票买入卖出最佳实际II)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  3. JS兼容性汇总

    1.  Frame  (1)问题:在IE中可以用window.top.frameId和window.top.frameName来得到该Frame所代表的Window,Firefox中只能用window ...

  4. 剑指offer--27.包含min函数的栈

    时间限制:1秒 空间限制:32768K 热度指数:252822 本题知识点: 栈 算法知识视频讲解 题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为 ...

  5. 如何在eclipse中安装ADT

    打开Eclipse,点击 Help -> Install New Software: 点击Add: 然后点击Archive,添加对应的上面的ADT-21.0.1.zip: OK后,再写上一个名字 ...

  6. Kotlin For Gank.io (干货集中营Kotlin实现)

    介绍 Kotlin,现在如火如荼,所以花了一点时间把之前的项目用Kotlin重构一下 原项目地址:https://github.com/onlyloveyd/GankIOClient 对应Kotlin ...

  7. I.MX6 give su command more permission

    /************************************************************************************ * I.MX6 give s ...

  8. 【英语】Bingo口语笔记(87) - 不要做某事的常见表达

  9. 数据分析笔试-sql

    题目说明及要求: 以下是模似数据库里的表单信息,请根据要求写出SQL语句 表1:职工信息 表结构如下: 表名:Employee 职工ID   职工姓名       入职年份       部门ID A1 ...

  10. Javascript 原型链资料收集

    Javascript 原型链资料收集 先收集,后理解. 理解JavaScript的原型链和继承 https://blog.oyanglul.us/javascript/understand-proto ...