```
public class Solution {
public boolean canPlaceFlowers(int[] flowerbed, int n) {
boolean left, right;
for (int i = 0; i < flowerbed.length; i++) {
if (flowerbed[i] == 1) continue;
left = (i == 0 || flowerbed[i-1] == 0)? true : false;
right = (i == flowerbed.length - 1 || flowerbed[i+1] == 0)? true : false;
if (left && right) {
n--;
flowerbed[i] = 1;
}
}
return n <= 0;
}
}
```