We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents d36f5b5 + 5cb92a1 commit e60ce4eCopy full SHA for e60ce4e
solution/0605.Can Place Flowers/Solution.py
@@ -0,0 +1,22 @@
1
+class Solution:
2
+ def canPlaceFlowers(self, flowerBed, n):
3
+ """
4
+ type flowerBed : List[int], n : int
5
+ rtype : bool
6
7
+
8
+ i = 0
9
+ while n > 0 and i < len(flowerBed):
10
+ if i == 0 and flowerBed[0] == 0: # for 1st Element
11
+ if len(flowerBed) == 1 or (len(flowerBed) > 1 and flowerBed[1] == 0):
12
+ n -= 1
13
+ flowerBed[0] = 1
14
+ elif i == len(flowerBed)-1 and flowerBed[i] == 0 and flowerBed[i-1] == 0: # for last element
15
16
+ flowerBed[i] = 1
17
+ elif flowerBed[i] == 0 and flowerBed[i-1] == 0 and flowerBed[i+1] == 0:
18
19
20
+ i += 1
21
22
+ return n==0
0 commit comments