Jump Game II
ID: 45
Given an array of non-negative integers nums
, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Your goal is to reach the last index in the minimum number of jumps.
You can assume that you can always reach the last index.
Idea
Similar to Jump Game I, but this time, keep track of a global max and a local max, which only when current index reach its local max, step should be increment
Iteratively check for the global max that can be achieved from a index, when index == local max, step+=1, update local max to global max. Otherwise, only increment current index
Code
Last updated