class Solution {
public:
int jump(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(n == 1) return 0;
vector<int> f(n,0);
int range = 0;
int tmp;
for(int i = 0; i < n; i++){
if(range >= n-1) return f[n-1];
tmp = i + A[i];
if(tmp > range){
for(int j = range+1; j <= tmp && j < n; j++){
f[j] = f[i]+1;
}
range = tmp;
}
}
return 0;
}
};
[leetcode]Jump Game II
最新推荐文章于 2019-05-13 13:40:05 发布