We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
55. 跳跃游戏
/** * @param {number[]} nums * @return {boolean} */ var canJump = function(nums) { if(nums[0] === 0 && nums.length > 1) { return false; } if(nums.length == 1) { return true; } const len = nums.length - 1, distances = []; //计算每个位置所能到达的最远距离 let i=0, j, max = Number.MIN_VALUE; while(i < len) { distances.push(nums[i] + i); let interval = i + nums[i]; for(j=i+1; j<interval && j <len; j++) { //计算范围内的最远距离 distances.push(nums[j] + j); } i = j; //判断当前最远距离是否可以继续循环 max = Math.max.apply(this, distances); if(max < j) break; } return max >= len; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
55. 跳跃游戏
The text was updated successfully, but these errors were encountered: