思路:用一个数字来存储到对应索引i的最少跳跃次数,ans[j]=Math.min(ans[j],ans[i]+1)
code:
class Solution {public int jump(int[] nums) {int n=nums.length;int ans[]=new int[n];for(int i=0;i<n;i++){ans[i]=Integer.MAX_VALUE;}ans[0]=0;for(int i=0;i<n-1;i++){for(int j=i+1;j<=i+nums[i]&&j<n;j++){ans[j]=Math.min(ans[j],ans[i]+1);}}return ans[n-1];}
}