Java 4 line-solution, can you beat it?


  • 5
    L
    public boolean canJump(int[] nums) {
           int maxReach = 0;
           for (int i = 0; i < nums.length && i <= maxReach; i++) 
                maxReach=Math.max(maxReach, nums[i]+i);
           return maxReach >= nums.length - 1;
    }

Log in to reply
 

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