605Can Place Flowers

来源:互联网 发布:上古卷轴5白雪捏脸数据 编辑:程序博客网 时间:2024/06/05 03:22

能种多少花儿

class Solution(object):
    def canPlaceFlowers(self, A, N):
        """
        :type flowerbed: List[int]
        :type n: int
        :rtype: bool
        """
        for i in range(len(A)):
            if (not A[i] and (i == 0 or A[i-1] == 0) 
                    and (i == len(A)-1 or A[i+1] == 0)):
                N -= 1
                A[i] = 1
        return N <= 0

原创粉丝点击