mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-08-02 02:17:53 +08:00
Add solution 605
This commit is contained in:
18
leetcode/0605.Can-Place-Flowers/605. Can Place Flowers.go
Normal file
18
leetcode/0605.Can-Place-Flowers/605. Can Place Flowers.go
Normal file
@ -0,0 +1,18 @@
|
||||
package leetcode
|
||||
|
||||
func canPlaceFlowers(flowerbed []int, n int) bool {
|
||||
lenth := len(flowerbed)
|
||||
for i := 0; i < lenth && n > 0; i += 2 {
|
||||
if flowerbed[i] == 0 {
|
||||
if i+1 == lenth || flowerbed[i+1] == 0 {
|
||||
n--
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
||||
if n == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user