题解 | #跳跃游戏(一)#

跳跃游戏(一)

http://www.nowcoder.com/practice/23407eccb76447038d7c0f568370c1bd

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型vector 
     * @return bool布尔型
     */
    bool canJump(vector<int>& nums) {
        // write code here
        int x=nums[0];
        for(int i=0;i<=x;++i){
            if(nums[i]+i>=nums.size()-1) return true;//从当前位置能跳到最后一个位置即可
            x=max(nums[i]+i,x);
        }
        return false;
    }
};
全部评论

相关推荐

Cherrycola01:0实习 0项目 约等于啥也没有啊 哥们儿这简历认真的吗
点赞 评论 收藏
分享
04-29 22:35
门头沟学院 Java
牛友说改了名字能收到offer:旧图新发查看图片
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务