Skip to content

Commit

Permalink
Create can-place-flowers.py
Browse files Browse the repository at this point in the history
O(n) efficient solution
  • Loading branch information
gabedonnan authored Mar 20, 2023
1 parent c520a4b commit cc5159c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions can-place-flowers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
for i in range(len(flowerbed)):
if [flowerbed[max(0,i-1)], flowerbed[i], flowerbed[min(len(flowerbed)-1, i+1)]] == [0,0,0]:
flowerbed[i] = 1
n -= 1
if n == 0:
return True
return False

0 comments on commit cc5159c

Please sign in to comment.