题目:
代码:
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
int ans=0;
int temp=1;
for(int i=0;i<flowerbed.size();i++){
if(flowerbed[i]==0) temp++;
else{
if(temp>0){
ans+=(temp-1)/2;
temp=0;
}
}
}
if(temp>0) ans+=temp/2;
return ans>=n;
}
};
总结:简单题,处理好两边界即可