文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
class Solution {
public:
int jump(vector<int>& nums) {
int current = 0;
int count = 0;
while(current < nums.size() - 1) {
count++;
if(current + nums[current] >= nums.size() - 1) {
break;
}
int distance = 0;
int index = current + 1;
int begin = current + 1;
int end = current + nums[current];
for(int i = begin; i <= end; i++) {
if(nums[i] + i > distance) {
distance = nums[i] + i;
index = i;
}
}
current = index;
}
return count;
}
};