0%

• 45. Jump Game II
• 55. Jump Game

### 55. Jump Game

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.

Determine if you are able to reach the last index.

For example: A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], return false.

C++

cover表示当前覆盖到的下标，

• cover < i 则无解
• 如果cover >= len(nums)-1，说明跳到了目的地，有解。
• 否则cover = max(cover, nums[i] + i) 即更新最大的跳到的位置

C++

Python

### 45. Jump Game II

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.

For example: Given array A = [2,3,1,1,4]

The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.)

Note: You can assume that you can always reach the last index.

DP超时，可以用类似55题的方法：

cur_cover表示当前能跳到的最远距离，last_cover表示上次最远可以跳到的距离。

C++

Python

• 45. Jump Game II
• 55. Jump Game