class Solution:
    def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
        l = len(flowerbed)
        if l == 1:
            if flowerbed[0] == 0 or n == 0:
                return True
            else:
                return False      
        for i in range(l):
            if flowerbed[i] == 0 and n > 0:
                if i == 0 :
                    if flowerbed[0] == 0 and flowerbed[1] == 0:
                        flowerbed[0] = 1
                        n -= 1
                elif i == l-1:
                    if flowerbed[i] == 0 and flowerbed[i-1] == 0:
                        flowerbed[i] = 1
                        n -= 1
                elif flowerbed[i-1] == 0 and flowerbed[i+1] == 0:
                    flowerbed[i] = 1
                    n -= 1
        if n == 0:
            return True
        return False
