45. Jump Game II
problem description
Given an array of non-negative integers, 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.
Example:
Note:
You can assume that you can always reach the last index.
algorithm thought
一次遍历解决问题,第一步能走到的地方就是nums[0],每到一个地方,确定当前位置能走到的最大值。在一步走完之后,确定下一个最大能走到的范围。
code
algorithm analysis
一次遍历数组,时间复杂度O(n)
Last updated