We need to justify a greedy solution.

Call a plot ready if the very first flower is allowed to be planted there.

Consider the left-most ready plot x (if it exists). If x+1 is not ready, then we increase our answer strictly by planting at x, since x does not disturb any ready plots. If x+1 is ready, then planting at x instead of x+1 is atleast as good, since x disturbs only {x, x+1}, whereas x+1 disturbs {x, x+1, x+2}.

Now our implementation is trivial. For each plot from left to right, if we can plant a flower there, then do so. We can plant a flower if the left neighbor is 0 (or we are on the left edge), AND the right neighbor is 0 (or we are on the right edge).

```
def canPlaceFlowers(self, A, N):
for i, x in enumerate(A):
if (not x and (i == 0 or A[i-1] == 0)
and (i == len(A)-1 or A[i+1] == 0)):
N -= 1
A[i] = 1
return N <= 0
```