Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
For example:
A = [2,3,1,1,4]
, return true
.
A = [3,2,1,0,4]
, return false
.
每一位数字代表你能跳的最大步数,判断给定数组能否从头跳转到队尾
1 public boolean canJump(int[] nums) { 2 int maxDepth = 0; 3 for (int i=0;i<nums.length;i++) 4 { 5 if(i> maxDepth) return false; 6 maxDepth = Math.max(maxDepth,i+nums[i]); 7 } 8 return true; 9 }