Skip to content

Commit 3c322da

Browse files
authored
Added Solution.py
1 parent 557cf9a commit 3c322da

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def canPlaceFlowers(self, flowerBed, n):
3+
"""
4+
type flowerBed : List[int], n : int
5+
rtype : bool
6+
"""
7+
8+
for i in range(len(flowerBed)):
9+
if i == 0 and flowerBed[0] == 0: # for 1st Element
10+
if len(flowerBed) == 1 or (len(flowerBed) > 1 and flowerBed[1] == 0):
11+
n -= 1
12+
elif i == len(flowerBed)-1 and flowerBed[i] == 0 and flowerBed[i-1] == 0: # for last element
13+
n -= 1
14+
elif flowerBed[i] == 0 and flowerBed[i-1] == 0 and flowerBed[i+1] == 0:
15+
n -= 1
16+
17+
return n==0

0 commit comments

Comments
 (0)