```
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
for(int i = 0; i < flowerbed.size(); ++i){
if(n == 0) return true;
if(flowerbed[i] == 1) continue;
//flowerbed[i] == 0
if(i == 0 || (i >= 1 && flowerbed[i-1] == 0)){
if(i == flowerbed.size()-1 || (i + 1 < flowerbed.size() && flowerbed[i+1] == 0)){
flowerbed[i] = 1;
n--;
}
}
}
return n == 0;
}
};
```