用一个变量存放当前所能到达的最远的下标位置
class Solution {
public boolean canJump(int[] nums) {
int farestIndex = 0;// 记录当前最远能到达的下标
for (int i = 0; i <= farestIndex && i < nums.length; i++){
if ((nums[i] + i) > farestIndex){
farestIndex = (nums[i] + i);
}
}
if (farestIndex >= (nums.length - 1))
return true;
return false;
}
}
标签:150,return,nums,int,farestIndex,面试,经典,下标
From: https://www.cnblogs.com/poteitoutou/p/18008343