An easy understanding Java solution


  • 0
    B

    We track backwards, to see if we could reach the beginning of the array.

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

Log in to reply
 

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