Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 657 Bytes

605.md

File metadata and controls

9 lines (5 loc) · 657 Bytes

605. Can Place Flowers

You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.

Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise.

Easy to understand. We just need to plant a flower when we see three 0s. and for the first one and last one we shall put an extra zero before and after them. In this case, all checking shall be done fore continuous 3 0s.

clearly, it's greedy.