Tuesday, February 16, 2016

LeetCode Q55: 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.

Different than Jump game II, this one only need to determine whether can reach the end. The situation where it can not reach the end is because all jumps stops at some cell with 0 possible steps. I use linear scan to solve the question. During scanning, keep updating the furthest  position can reach. Return false when the furthest position stop updating.



Round 2 Solution:
Check whether current location can be reached by previous steps.

No comments:

Post a Comment