22 lines
362 B
Go
22 lines
362 B
Go
package q605
|
|
|
|
func canPlaceFlowers(flowerbed []int, n int) bool {
|
|
for i := 0; i < len(flowerbed); i++ {
|
|
if flowerbed[i] == 1 {
|
|
i++
|
|
continue
|
|
}
|
|
|
|
if (i == 0 || flowerbed[i-1] == 0) && (i == len(flowerbed)-1 || flowerbed[i+1] == 0) {
|
|
flowerbed[i] = 1
|
|
i++
|
|
n--
|
|
if n <= 0 {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return n == 0
|
|
}
|
|
|
|
var _ = canPlaceFlowers
|