jump-game

Posted 修修55

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jump-game相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    bool canJump(int A[], int n) {
        if(n<=1)
            return true;
        
        int reach = 1;
        for(int i=0;i<reach&&reach<n;++i){
            reach = max(reach,i+1+A[i]);
        }
        
        return reach >= n;
    }
};

//判断是否能调到结尾。贪心算法。记录每次能跳到的最大距离位置。

以上是关于jump-game的主要内容,如果未能解决你的问题,请参考以下文章