leetcode_55
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
Solutions
We say a point is a good point if we can jump to it.
greedy backward O(n)
A point can jump to the last good point(the end) if only it can jump to the first good point left the last good point.
greedy forward O(n)
May be practically faster than the first version with pre-exit.
In each step we record the currently reacheable distant point.
If the maximum index is smaller than the current index. There is no way to get to the last.
Pre-exit when we already can get to the last.
Last updated
Was this helpful?