Leetcode 55 - Jump game

Note:

• Greedy
• For each element, get the furthest index you can reach and update the limit of for loop. If index >= length - 1, means we can get to the end.
• DP
• dp[i] means the furthest index you can get from position i.
• (Note: it’s not how many steps you can take the most, it’s the INDEX)
• When dp[i-1] > i, it means from i-1, we can get to i or even further. So, we need to pick the bigger one

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.

Example

Greedy

DP

DFS