public class Solution {
public boolean canJump(int[] nums) {
if (nums == null || nums.length < 2) return true; // [0] return true;
int len = nums.length;
int farthest = nums[0];
int i = 1;
//while (i < len && i <= farthest) {
while (i <= farthest) {
farthest = Math.max(farthest, nums[i] + i);
i++;
if (farthest >= len - 1) return true;
}
return false;
}
}
public class Solution {
public boolean canJump(int[] nums) {
if(nums.length == 1) return true;
if (nums[0]==0 && nums.length != 1)
return false;
for(int curr = nums.length-2; curr>=0;curr--){
if(nums[curr] == 0){
int neededJumps = 1;
while(neededJumps > nums[curr]){
neededJumps++;
curr--;
if(curr < 0) return false;
}
}
}
return true;
}
}