-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path605.py
More file actions
21 lines (19 loc) · 756 Bytes
/
605.py
File metadata and controls
21 lines (19 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
c = 0
if (len(flowerbed) == 1):
return (n == 0 or (n == 1 and flowerbed == [0]))
for i in range(len(flowerbed)):
if (i == 0):
if flowerbed[i+1] == 0 and flowerbed[i] == 0:
flowerbed[i] = 1
c += 1
elif (i == len(flowerbed)-1):
if (flowerbed[i-1] == 0 and flowerbed[i] == 0):
flowerbed[i] = 1
c += 1
else:
if (flowerbed[i-1] == 0 and flowerbed[i+1] == 0 and flowerbed[i] == 0):
flowerbed[i] = 1
c += 1
return n <= c