Simple Java Solution O(n) Time, O(1) Space, Forward Coverage Check


  • 0
    A
    public class Solution {
        public boolean canJump(int[] nums) {
            if(nums.length < 2) return true;
            if(nums[0] == 0) return false;
            
            int i = 1;
            int coverage = nums[0];
            while(i < nums.length - 1) {
                coverage = Math.max(coverage - 1, nums[i]);
                if(coverage <= 0) return false;
                ++i;
            }
            return true;
        }
    }
    

Log in to reply
 

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