clean java dp


  • 0
    N

    if(nums.length == 0 || nums.length == 1){
    return true;
    }
    if(nums[0] == 0){
    return false;
    }

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

Log in to reply
 

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