Very simple O(n) Java 9ms solution.


  • 0
    I

    public class Solution {
    public int jump(int[] nums) {
    if(nums.length==0||nums.length==1) return 0;
    int[] res = new int[nums.length];
    int max=0;
    for(int i=0;i<nums.length-1;i++){
    int temp = nums[i];
    if(max>=temp+i){
    continue;
    }
    int oldmax = max;
    max = temp+i;
    for(int j=oldmax+1;j<=max;j++){
    if(j<nums.length){
    res[j]=res[i]+1;
    }
    }
    }
    return res[nums.length-1];
    }
    }


Log in to reply
 

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