标签: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 };
首位单独处理,中间的好处理,问题不大。
标签:null als i++ code std wing color turn bool
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9144439.html