My Straightforward Java Solution


  • 0
    M
    public boolean canJump(int[] nums) {
            if (nums == null || nums.length == 0) return false;
    		int n = nums.length;
    		if (n == 1) return true;
    		int max = 0, i = 0;
    		while (i <= max && i < n) {
    			max = Math.max(max, nums[i] + i);
    			if (max >= n - 1) return true;
    			++i;
    		}
    		return max >= n - 1;
        }
    

Log in to reply
 

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