rocksc30 / LeetCode

用于力扣刷题打卡
2 stars 0 forks source link

55. 跳跃游戏 #85

Open Ni-Guvara opened 1 year ago

Ni-Guvara commented 1 year ago
class Solution {
public:
    bool canJump(vector<int>& nums) {

        int right = nums.size() - 2;

        int cnt = 0;
        vector<bool> recd(nums.size() , false);
        recd[right + 1] = true;
        while(right >= 0)
        {
            if(nums[right] > 0 && cnt == 0)
            {
                recd[right] = recd[right + 1];
                cnt = 0;
            }
            else
            {
                ++cnt;
                if(nums[right] >= cnt)
                {
                    recd[right] = recd[right + cnt];
                    cnt = 0;
                }

            }
            --right;
        } 
        return recd[0];
    }
};