class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
if len(flowerbed) == 1:
if flowerbed[0] == 0:
return 1 >= n
else:
return 0 >= n
else:
i = 0
count = 0
while i < len(flowerbed):
if i == 0 and flowerbed[0] == 0 and flowerbed[1] == 0:
flowerbed[0] = 1
count += 1
i += 2
elif i < len(flowerbed) - 1 and flowerbed[i - 1] == 0 and flowerbed[i] == 0 and flowerbed[i + 1] == 0:
flowerbed[i] = 1
count += 1
i += 2
elif i == len(flowerbed) - 1 and flowerbed[i - 1] == 0 and flowerbed[i] == 0:
flowerbed[i] = 1
count += 1
i += 2
else:
i += 1
return count >= n
相关文章
- 01-20Qt5配置OpenCV之问题总结
- 01-20Selenium常见报错问题解决方案(1)- 先来认识下selenium常见异常类
- 01-20C语言判断文件指针是否结尾的问题
- 01-20dorado问题查询&快捷键重命名
- 01-20关于maven-jetty-plugin 自动重启问题
- 01-20relief中visio图出现问题处理
- 01-20【记录】关于macOS每次都要调用source ~/.bash_profile使环境变量生效的问题
- 01-20海思AI芯片(HI35xx):tensorflow转caffemodel之环境和权限问题
- 01-20数组连续区间均值最大值问题
- 01-20小数精度的一些问题