Title Link: https://leetcode.com/problems/jump-game/
Topic:
Given an array of non-negative integers, you is initially positioned at the first index of the array.
Each element of the array represents your maximum jump length is at that position.
Determine if you is able to reach the last index.
For example:
A = [2,3,1,1,4], return true.
A = [3,2,1,0,4], return false.
Ideas:
Returns False when the number of steps that can be moved forward is 0
Otherwise try to move forward and update the number of steps you can move forward.
Algorithm:
public Boolean Canjump (int[] nums) {if(Nums.length==0|| Nums.length==1)return true;intMaxstep = nums[0]; for(inti =1; I < Nums.length; i++) {if(Maxstep = =0)return false; maxstep--;if(Maxstep < nums[i]) {maxstep = nums[i]; }if(Maxstep + i >= nums.length-1) {return true; } }return false; }
"Leetcode" Jump Game