Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 511 Bytes

2022-12-26.md

File metadata and controls

19 lines (15 loc) · 511 Bytes

题目

  1. Jump Game

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.

Return true if you can reach the last index, or false otherwise.

思路

代码

var canJump = function(nums) {
  let farthest = 0
  for (let i = 0; i <= farthest && i < nums.length; i++) {
    farthest = Math.max(farthest, i + nums[i])
  }
  return farthest >= nums.length - 1
}