class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
for(int i=0;i<flowerbed.size();i++)
if(flowerbed[i]==0){
if((i==0||flowerbed[i-1]==0)&&(i==flowerbed.size()-1||flowerbed[i+1]==0)){
flowerbed[i]=1;
n--;
}
}
return n<=0;
}
};
605 种花问题
最新推荐文章于 2021-05-28 21:43:32 发布