您的位置:首页 > 编程语言 > Go语言

Algorithms—45.Jump Game II

2015-09-07 14:49 543 查看
思路:动态规划。

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: