LeetCode Jump Game Series
55 jump game: check if can reach the last index: iterate the whole nums, and find out if we can reach the last for loop, everytime find out the furtherest we can get, if the furthest can not reach i+1, it means we will stuck in this point.
45 jump game2: get the min steps the reach the last index. using greedy, each time, we use current range to get a new range which is every position on current range can get farthest. if we can reach the last index with in the range, then it is definitely the minimum step. it’s quite like level order tranverse. we use current level to generate next level
1306 jump game3: check if you can reach any index with value is 0. and you can choose to jump i+nums[i] OR i-nums[i], and we can not jump outside of array at anytime. solution: use recursion, it is very easy to understand, each time we visit some point, we use a kind f genius way to mark it as visited, and when ever we encounter this visited place, we know it is a loop and this way is not walk.
1345 jump game4: get the min steps to reach the last index. each time, you can move forward or backward with 1 steps(but can exceed the index range) OR jump to any index j if nums[i]==nums[j]. solution: in this problem, we only can move forward or backward by 1 or move the index where values are the same to current. and it asks us to get the minimum step like LC45. and still, any time we can’t jump outside. this problem uses bfs, based on a hashmap, the key is one value of nums, and the value is all the index that has the same value as the key. then we make bfs, the level is the step.
1340 jump game5: this is harder to description in words, so refer to: https://leetcode.com/problems/jump-game-v/. so this problem is basically move max steps as given and can’t outside indexes also. we can freely choose any starting point, we need to return the maximum of indexes we can visited. solution: this problem uses memo+dfs. the general idea is: we calculate the max step for every start i. how do we calculate the max step for fixed i? we iterate every possible steps and return the max one(that’s what those two loops for).
403 frog jump: this problem is much like all those previous jump game problem. but the rules are not the same: initilize in index 0, and the first step it can go is 1 step. and for every move this frog made later, it can move k-1,k or k+1 steps, where k is the last move steps it take. we need to check if it can cross the river safely. we can use two method: memo OR dp. they are both easy to understand. it’s general brute force, which means we tried every possible move ways.

浙公网安备 33010602011771号