605.种花问题
class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
l = len(flowerbed)
news = [0] * (l+2)
ans = 0
for i in range(1,l+1):
news[i] = flowerbed[i-1]
for i in range(1,l+1):
if news[i-1] == 0 and news[i] == 0 and news[i+1] == 0:
news[i] = 1
ans += 1
if ans >= n:
return True
else:
return False