55. Jump Game

只要找到一个方式可以到达,那当前位置就是可以到达的,所以可以break

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
class Solution {
public:
    bool canJump(vector<int>& nums) {
        int length = nums.size();
        if(length <= 0)
            return false;
        vector<bool> dp(length,false);
        dp[0] = true;
        for(int i = 1;i < length;i++){
            for(int j = i - 1;j >= 0;j--){
                if(dp[j] == true && i - j <= nums[j]){
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[length-1];
    }
};

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄