605. Can Place Flowers
class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
cnt = 0
pre = 0
for i in range(len(flowerbed)):
if pre == 0 and flowerbed[i] == 0:
if i == len(flowerbed) - 1 or flowerbed[i+1] == 0:
cnt += 1
flowerbed[i] = 1
pre = flowerbed[i]
return cnt >= n