Java 2ms solution, easy, simple


  • 0
    R
    public boolean canJump(int[] nums) {
        if(nums==null || nums.length==0){
            return false;
        }
        if(nums[0]==0&&nums.length>1){
            return false;
        }
        int current=nums[0];
        for(int index=1; index<nums.length; index++){
            current--;
            if(nums[index]>current){
                current=nums[index];
            }
            if(current==0&&index<nums.length-1){
                return false;
            }
        }
        return true;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.