4 lines Java solution with O(n)


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

Log in to reply
 

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