Skip to content

Commit

Permalink
Time: 0 ms (100%), Space: 8.5 MB (98.86%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Jan 28, 2025
1 parent c6c5d68 commit 36b9002
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions 0055-jump-game/0055-jump-game.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
func canJump(nums []int) bool {
n := len(nums) - 1
for i := n - 1; i >= 0; i-- {
if nums[i] + i >= n {
n = i
cur := 0
for i, v := range nums {
if cur < i {
return false
}

if i + v > cur {
cur = i + v
}
}

return n == 0
return cur >= len(nums) - 1
}

0 comments on commit 36b9002

Please sign in to comment.