Problem
A flowerbed is a row of plots: 1 is planted, 0 is empty. Flowers may not be planted in adjacent plots. The bed you are given already follows that rule. Return true if you can plant n new flowers without breaking it.
Example 1
- Input
- flowerbed = [1, 0, 0, 0, 1], n = 1
- Output
- true
Example 2
- Input
- flowerbed = [1, 0, 0, 0, 1], n = 2
- Output
- false
Example 3
- Input
- flowerbed = [0, 0, 1, 0, 0], n = 2
- Output
- true
- Why
- both ends
Constraints
1 <= flowerbed.length <= 2 * 10^4flowerbed[i] is 0 or 1.No two adjacent plots are both 1.0 <= n <= flowerbed.length