要求:找0放1,1不能相邻
思路:简单
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
const int m = flowerbed.size();
for(int i = 0; i < m; ++i)
if(!flowerbed[i]&&(i==m-1||!flowerbed[i+1])&&(i==0||!flowerbed[i-1])){
flowerbed[i] = 1;
--n;
}
return n <= 0;
}
};