Simple Java solution bottom up


  • 0
    P

    public class Solution {
    public boolean canJump(int[] nums) {
    if(nums != null && nums.length > 0){
    if(nums.length == 1){
    return true;
    }
    int cnt = 1;
    boolean exists = false;
    for(int i = nums.length - 2 ; i >= 0 ; i--){
    if(nums[i] > 0 && nums[i] >= cnt){
    exists = true;
    cnt = 1;
    }else{
    exists = false;
    cnt++;
    }
    }
    return exists;
    }
    return false;
    }

    }


Log in to reply
 

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