add new solutions
This commit is contained in:
parent
9a10695e8c
commit
ca24d0a56a
30 changed files with 697 additions and 16 deletions
22
solutions/6/q605/solution.go
Normal file
22
solutions/6/q605/solution.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue