#605

Can Place Flowers

pupil · 525 · lc easy +28 · verified · 29.1% accepted · 7,357 likes · top 6%

play →

Description

A flowerbed is represented by an integer array flowerbed of 0s (empty) and 1s (occupied). Flowers may not be planted in neighboring plots. Given flowerbed and an integer n, return true if n additional flowers can be planted without breaking the adjacency rule, or false otherwise.

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

Code

1
2
3