Leetcode#55 Jump Game

原题地址

跟Jump Game II(见这篇文章)不同的地方在于,只需要判断能否到达终点即可

遍历每个位置,更新能够到达的范围,最后看看范围是否覆盖了终点

代码:

 1 bool canJump(int A[], int n) {
 2         int range = 0;
 3         int pos = 0;
 4         
 5         while (pos < n && pos <= range) {
 6             range = max(range, pos + A[pos]);
 7             pos++;
 8         }
 9         
10         return range + 1 >= n;
11 }
原文地址:https://www.cnblogs.com/boring09/p/4252956.html