Jump Game II

You are given a 0-indexed array of integers nums of length n. Each element nums[i] represents the maximum length of a forward jump from index i. You are initially positioned at nums[0], and you must determine the minimum number of jumps needed to reach nums[n - 1]. It is guaranteed that you can reach the last index.

Constraints

  • 1 <= nums.length <= 10000
  • 0 <= nums[i] <= 1000
  • It's guaranteed that you can reach nums[n - 1].
Saving… · 2 lines
class Solution:
def jumpGameII(self, nums: List[int]) -> int:
Console

Click Run to execute sample tests.