O(n) DP in Java


  • 0
    S

    //maximum steps possible at any point(except at the last index) should be >0
    public class Solution {
    public boolean canJump(int[] nums) {
    if(nums==null || nums.length==0){
    return true;
    }
    int max = nums[0];

        for(int i=0; i< nums.length-1; i++){
            max=Integer.max(--max,nums[i]);
            if(max==0){
                return false;
            }
        }
        return true;       
    }
    

    }


Log in to reply
 

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