【LeetCode-55】Jump Game

来源:互联网 发布:怎么申请淘宝卖家 编辑:程序博客网 时间:2024/05/20 09:06

这道题自己实在没思路,然后看到别人写的,自己还是太弱了,fighting

public class ImportantJumpGame {public boolean canJump(int[] nums) {        if(nums.length == 0 || nums.length == 1){        return true;        }                int maxStep = nums[0];        for(int i = 1;i < nums.length;i ++){        //每次先判断可前进的最大步数,为0,则不能移动        if(maxStep == 0){        return false;        }                maxStep --;                if(nums[i] > maxStep){        maxStep = nums[i];        }                if(maxStep + i >= nums.length - 1){        return true;        }        }                return true;    }}



0 0
原创粉丝点击