function canJump(nums)
furthest := 0
for i from 0 to length of nums - 1
if i > furthest then
return false
furthest := max(furthest, i + nums[i])
return true
Time: . Space: .
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
The code
function canJump(nums)
furthest := 0
for i from 0 to length of nums - 1
if i > furthest then
return false
furthest := max(furthest, i + nums[i])
return true
Time: . Space: .