2ms simple JAVA solution


  • 1
    O
    public class Solution {
        public boolean canJump(int[] nums) {
            int index_needed=nums.length-1;
            for (int i=nums.length-1;i>=0;--i){
                if (nums[i]>=index_needed-i)
                index_needed=i;
            }
            return index_needed==0;
        }
    }

  • 0

    public boolean canJump(int[] nums) {
    int max = 0;
    for (int i = 0; i < nums.length && max >= i && max < nums.length - 1; i++)
    max = Math.max(nums[i] + i, max);
    return max >= nums.length - 1 ? true : false;
    }


Log in to reply
 

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