Jump Game 题解
Last updated
Was this helpful?
Last updated
Was this helpful?
题目来源:
> 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.
解题思路:
过每个index查看能到的最远的index,若当前最远的比遍历index还小或者相等时就走不下去了。
f[i]表示走到第A[i]时, 多余的最大步数。 f[i] = max(f[i-1], A[i-1])-1