Simple Java O(n) solution, easy to understand


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

  • 0
    R

    excellent , thanks


Log in to reply
 

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