码迷,mamicode.com
首页 > 其他好文 > 详细

605. Can Place Flowers

时间:2018-06-06 15:42:12      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:null   als   i++   code   std   wing   color   turn   bool   

 1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     bool canPlaceFlowers(vector<int>& flowerbed, int n) 
12     {
13         int sz=flowerbed.size();
14         int count=0;
15         if(flowerbed[0]==0&&flowerbed[1]==0)
16         {
17             flowerbed[0]=1;
18             count++;
19         }
20         for(int i=1;i<sz-1;i++)
21         {
22             
23             if(flowerbed[i]==0&&flowerbed[i-1]==0&&flowerbed[i+1]==0)
24             {
25                 flowerbed[i]=1;
26                 count++;
27             }
28         }
29         if(flowerbed[sz-2]==0&&flowerbed[sz-1]==0)
30             count++;
31         return n<=count;
32     }
33 };

首位单独处理,中间的好处理,问题不大。

605. Can Place Flowers

标签:null   als   i++   code   std   wing   color   turn   bool   

原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9144439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!