这道题的意思就是给你一个数组(或者容器),从下标0作为初始位置让你遍历,如果数组里每个值代表从其所在的下标处你最大能从后跳几个位置,判断一下你能不能跳到最后一个下标位置去
class Solution {
public:
bool canJump(vector<int>& nums) {
int distance = 0;
for(vector<int>::iterator it = nums.end() - 1 ; it >= nums.begin(); it--,distance++){
if(*it >= distance){
distance = 0;
}
if(it == nums.begin() && *it >= distance)
return true;
}
return false;
}
};