题目链接:55. 跳跃游戏 - 力扣(LeetCode)
数组的元素表示可以跳的最大长度,要判断能不能跳到最后
不断更新可以跳到的最远距离,如果当前的位置大于可跳最远距离,说明不行
class Solution {
public:bool canJump(vector<int> &nums) {int farthest = 0;for (int i = 0; i < nums.size(); ++i) {if (i > farthest)return false;farthest = max(farthest, i + nums[i]);}return true;}
};