Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (21 sloc) 335 Bytes
package main
import "fmt"
func canJump(nums []int) bool {
reach := 0
for i, num := range nums {
if reach >= len(nums)-1 {
return true
}
if 0 == num && reach <= i {
return false
}
if i+num > reach {
reach = i + num
}
}
return false
}
func main() {
nums := []int{3, 2, 1, 0, 4}
fmt.Println(canJump(nums))
}
You can’t perform that action at this time.