605_Can Place Flowers
605. Can Place Flowers
Level: easy
Tag: array
Question
Example 1
Example 2
Idea
Important trick: add 0 at the beginning and in the end of flowerbed. This action won't change if the first and last plot can plant flower.
Scan every plot in the original flowerbed, if it's empty, the plot on the left is empty and the plot on the right is also empty, then this plot can plant flower.
Count how many plots can plant flowers, and compare with n
.
.
Complexity
Time:
Space:
Solution
Last updated