class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
flowerbed.insert(flowerbed.begin(), 0); //简化判断
flowerbed.push_back(0);
for(int i = 1; i < flowerbed.size() - 1; ++i){
if(!flowerbed[i - 1] && !flowerbed[i] && !flowerbed[i + 1]){
flowerbed[i] = 1;
--n;
}
if(n <= 0){
return true;
}
}
return false;
}
};
09-03
1042
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-02
1214
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-06