Java DP Solution, O(1) space O(n) runtime, easy to understand

  • 0

    From tail to head, check if current position could reach the closest to current position that reach all the way to the end.

    public class Solution {
        public boolean canJump(int[] nums) {
            boolean dp = true;
            int last = nums.length - 1;
            for(int i = last; i >= 0; i--){
                if(nums[i] >= last - i){
                    dp = true;
                    last = i;
                    dp = false;
            return dp;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.