Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
- counter = 0
- for i in range(len(flowerbed)):
- if flowerbed[i]==0:
- # check on the left
- empty_left = i==0 or flowerbed[i-1]!=1
- # check on the right
- empty_right = i==len(flowerbed)-1 or flowerbed[i+1]!=1
- # if both are empty, place the flower
- if empty_left and empty_right:
- # plan the godamn flower
- flowerbed[i] = 1
- n=n-1
- if n==0:
- return True
- return False
Add Comment
Please, Sign In to add comment