55. 跳跃游戏(LeetCode)(贪心)
class Solution {
public:
bool canJump(vector<int>& nums) {
//顺序遍历,中途断则跳不到
for(int i = 0, maxlen = 0; i < nums.size(); ++i){
if(maxlen < i) return false;
maxlen = max(maxlen, i + nums[i]);
}
return true;
}
};

浙公网安备 33010602011771号