Skip to content

LC 0605 [E] Can Place Flowers

Code with Senpai edited this page Jan 11, 2022 · 1 revision
class Solution:
    def canPlaceFlowers(self, A, N):
        for i in range(len(A)):
            # is 0 and left is clear and right is clear
            if (A[i] == 0 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
Clone this wiki locally