leetcode605
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的更多相关文章
- [Swift]LeetCode605. 种花问题 | Can Place Flowers
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, ...
- Leetcode605.Can Place Flowers种花问题
假设你有一个很长的花坛,一部分地块种植了花,另一部分却没有.可是,花卉不能种植在相邻的地块上,它们会争夺水源,两者都会死去. 给定一个花坛(表示为一个数组包含0和1,其中0表示没种植花,1表示种植了花 ...
随机推荐
- poj1274
题解: 二分图匹配 裸题匈牙利匹配 代码: #include<cstdio> #include<cstring> #include<cmath> #include& ...
- 内存保护机制及绕过方案——利用未启用SafeSEH模块绕过SafeSEH
前言:之前关于safeSEH保护机制的原理等信息,可在之前的博文(内存保护机制及绕过方案中查看). 利用未启用SafeSEH模块绕过SafeSEH ⑴. 原理分析: 一个不是仅包含中间语言(1L)且 ...
- tomcat映射物理路径
<Context path="/woyoubaoweb/upload" docBase="/opt/file/image/woyoubaoweb/upload&qu ...
- 2017.11.23 display fun --STM8
unsigned char disp_mode;unsigned char disp_last_mode;unsigned char disp_sub_mode;unsigned char disp_ ...
- 【python】使用asyncore进行异步通信
参考博文:http://blog.csdn.net/livefun/article/details/8721772 参考博文:https://www.cnblogs.com/tomato0906/ar ...
- 《Drools7.0.0.Final规则引擎教程》第2章 追溯Drools5的使用
2.1 Drools5简述 上面已经提到Drools是通过规则编译.规则收集和规则的执行来实现具体功能的.Drools5提供了以下主要实现API: KnowledgeBuilder Knowledge ...
- 边缘检测︱基于 HED网络TensorFlow 和 OpenCV 实现图片边缘检测
本文摘录自<手机端运行卷积神经网络的一次实践 – 基于 TensorFlow 和 OpenCV 实现文档检测功能> 只截取感兴趣 的片段. . 一.边缘检测 1.传统边缘检测 Google ...
- Sublime Text 3打开gbk编码的文件中文乱码的问题
正在开发Wordpress主题,网上下载了一个博客模板,打开之后,发现里面的中文全是乱码 毕竟这玩意是外国人的东西,gbk是中文专用的编码,不支持很正常. 网上查了一下资料,需要安装一个Convert ...
- Golang Printf、Sprintf 、Fprintf 格式化
/* %v 输出结构体 {10 30} %+v 输出结构体显示字段名 {one:10 tow:30} %#v 输出结构体源代码片段 main.Point{one:10, tow:30} %T 输出值的 ...
- 设计模式之原型(prototype)模式
相信大多数的人都看过<西游记>,对孙悟空拔毛变出小猴子的故事情节应该都很熟悉.孙悟空可以用猴毛根据自己的形象复制出很多跟自己一模一样的小猴兵出来,其实在设计模式中也有一个类似的模式,我们可 ...