Skip to content

Commit

Permalink
Time: 13 ms (55.89%), Space: 6.1 MB (84.57%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Sep 27, 2024
1 parent a16791f commit 0a8199f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions 0605-can-place-flowers/0605-can-place-flowers.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
func canPlaceFlowers(flowerbed []int, n int) bool {
num := 0
for i := 0; i < len(flowerbed); i++ {
if flowerbed[i] == 0 && (i == 0 || flowerbed[i-1] == 0) && (i == len(flowerbed) - 1 || flowerbed[i+1] == 0) {
num += 1
flowerbed[i] = 1
if flowerbed[i] == 0 {
if (i == 0 || flowerbed[i-1] == 0) && (i == len(flowerbed) - 1 || flowerbed[i+1] == 0) {
n--
flowerbed[i] = 1
}
}
}

return num >= n

return n <= 0
}

0 comments on commit 0a8199f

Please sign in to comment.