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
原题链接
先明确,题目给出的非负整数数组中的每个位置的数字都对应着其最大的跳跃能力,要求我们判断能否到达最后一个下标。
到达或是超过都是可以满足要求的,因为每个位置的数字代表的是其最大的跳跃能力,而不是固定的跳跃能力(大富翁游戏)。
所以只需要判断能否到达终点即可:
i + nums[i]
const camJump = function(nums) { let canJumpMax = 0 let len = nums.length for (let i = 0; i < len; i++) { if (i > canJumpMax) { return false } canJumpMax = Math.max(canJumpMax, i + nums[i]) } return true }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
先明确,题目给出的非负整数数组中的每个位置的数字都对应着其最大的跳跃能力,要求我们判断能否到达最后一个下标。
到达或是超过都是可以满足要求的,因为每个位置的数字代表的是其最大的跳跃能力,而不是固定的跳跃能力(大富翁游戏)。
所以只需要判断能否到达终点即可:
i + nums[i]
也就是当前位置能够跳到的最远位置。The text was updated successfully, but these errors were encountered: