Java Solution


  • 0
    S

    public class Solution {
    public int jump(int[] nums) {
    int n = nums.length;
    if(n == 1)
    return 0;
    int dp[] = new int[n];
    dp[0] = 0;
    for(int i = 1; i < n ;i++) {
    dp[i] = Integer.MAX_VALUE;
    }
    for(int i = 1; i < n; i++) {
    for(int j = 0; j < i; j++) {
    if(nums[j] + j >= i) {
    dp[i] = Math.min(1 + dp[j] , dp[i]);
    break;
    }
    }
    }
    if(dp[n-1] == 0 || dp[n-1] == Integer.MAX_VALUE)
    return 0;
    else
    return dp[n-1];

    }
    

    }


Log in to reply
 

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