55. 跳跃游戏(LeetCode)(贪心)

55. 跳跃游戏

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;
    }
};
posted @ 2025-03-12 20:43  awei040519  阅读(13)  评论(0)    收藏  举报