```
public bool CanPlaceFlowers(int[] flowerbed, int n)
{
if (flowerbed == null || flowerbed.Length == 0)
{
return false;
}
var idx = 0;
while(n > 0 && idx < flowerbed.Length-1)
{
if (flowerbed[idx] != 1)
{
if (flowerbed[idx+1] == 0 && (idx == 0 || flowerbed[idx-1] == 0))
{
flowerbed[idx] = 1;
n--;
}
}
idx++;
}
if (n > 0 && flowerbed[idx] == 0 && (idx == 0 || flowerbed[idx - 1] == 0))
{
n--;
}
return n == 0;
}
```