class : def canPlaceFlowers(self, flowerbed, n): """ :type flowerbed: List[int] :type n: int :rtype: bool """ cnt = 0 flowerbed = [0] + flowerbed + [0] for i in range(1, len(flowerbed)-1): if flowerbed[i] == flowerbed[i-1] == flowerbed[i+1] == 0: flowerbed[i] = 1 cnt += 1 return cnt >= n
|
近期评论