贪心
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
int m = flowerbed.size();
int pre = -1;
for(int i=0;i<m;i++){
//寻找区间
if(flowerbed[i]==1){
if(pre<0){
n-=i/2;
}else{
n-=(i-pre-2)/2;
}
pre = i;
}
}
if(pre<0){
n-=(m+1)/2;
}else{
n-=(m-pre-1)/2;
}
return n<=0;
}
};
标签:605,pre,int,flowerbed,种花,LeetCode
From: https://www.cnblogs.com/poteitoutou/p/16874654.html