题目地址:链接
思路: 每次记录能到达的最远距离,遍历结束后,如果能到达最后一位,return true,否则return false
function canJump(nums: number[]): boolean {
const n = nums.length;
let nowMaxJump = 0;
for(let i = 0; i <= nowMaxJump && i < n; i ++) {
nowMaxJump = Math.max(nowMaxJump, nums[i] + i);
}
return nowMaxJump >= n - 1 ? true : false
};
8万+

被折叠的 条评论
为什么被折叠?



