class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
if n==0:
return True
if len(flowerbed)<=2:
for i in flowerbed:
if i==1 or n>1:
return False;
return True;
num=0
if(flowerbed[0]==0 and flowerbed[1]==0):
flowerbed[0]=1
num+=1
for i in range(1,len(flowerbed)-1):
i1=flowerbed[i-1]
i2=flowerbed[i]
i3=flowerbed[i+1]
if(i1==0 and i2==0 and i3==0):
flowerbed[i]=1
num+=1
if(flowerbed[-1]==0 and flowerbed[-2]==0):
num+=1
return num>=n
直接暴力解