Skip to content

Commit f1f4341

Browse files
committed
add solution in golang: 605. Can Place Flowers
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent 612c32f commit f1f4341

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
func canPlaceFlowers(flowerbed []int, n int) bool {
4+
empty := 0
5+
if flowerbed[0] == 0 {
6+
empty = 1
7+
}
8+
9+
for _, f := range flowerbed {
10+
if f == 0 {
11+
empty++
12+
} else {
13+
n -= (empty - 1) / 2
14+
empty = 0
15+
}
16+
}
17+
n -= empty / 2
18+
19+
return n <= 0
20+
}

0 commit comments

Comments
 (0)