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表示种植了花 ...
 
随机推荐
- 启动代码之开iCache
			
1.什么是cache,有什么用 cache是一种内存,叫高速缓存.从容量来说:CPU < 寄存器 < cache < DDR从速度来说:CPU > 寄存器 > ca ...
 - TCPL学习毕节:第六章hash表
			
对于P126的哈希表构成: struct nlist *install(char *name, char *defn) { struct nlist *np; unsigned hashval; if ...
 - 《Java程序员职场全攻略 从小工到专家》 - 书摘精要
			
(前言) 学习招式在次,提升内力才是最主要的: (P10) 选择一门编程语言,只是入门的途径.过分依赖编程语言,只会让自己成为代码高手,而不是开发大牛,要知道编程语言只是一种工具,更重要的是编程思想: ...
 - Tinymce group plugin
			
本文介绍一个tinymce插件,用来组合显示下拉的按钮.基于4.x,不兼容3.x. 以前 配置toolbar功能按钮 需要 toolbar1: "code undo red ...
 - 【SQL查询】查询结果翻译成其他值_decode
			
decode()函数简介: 主要作用:将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明): 使用方法: Select decode(columnname,值1,翻译值1,值2,翻译值2,.. ...
 - Android event logcat的研究
			
经常有这样的需求:在程序A启动之后,在这个程序上覆盖一个界面,让用户输入密码后才能启动程序A,这类场景主要集中在安全软件中. 那应该怎样得知某某程序启动了,系统没有相应的广播,这很难知道程序启动了. ...
 - SpringMVC札集(02)——SpringMVC入门完整详细示例(下)
			
自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...
 - 深入理解UE4宏定义—— GENERATED_BODY
			
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/72834164 作者:car ...
 - Markdown list状态下插入代码
			
/***************************************************************************** * Markdown list状态下插入代 ...
 - (效果五)js获取客户端ip地址及浏览器信息
			
在前端开发的时候,有时候为了测试需要得到访问客户的ip地址.虽说是后端来做的,但是我们前端也可以完成. 先说下获取用户ip地址,包括像ipv4,ipv6,掩码等内容,但是大部分都要根据浏览器的支持情况 ...