LintCode-跳跃游戏
2015-05-21 20:17
169 查看
给出一个非负整数数组,你最初定位在数组的第一个位置。
数组中的每个元素代表你在那个位置可以跳跃的最大长度。
判断你是否能到达数组的最后一个位置。
样例
A = [2,3,1,1,4],返回 true.
A = [3,2,1,0,4],返回 false.
分析:遍历一遍,记录可走的点可以达到的最远点
代码:
数组中的每个元素代表你在那个位置可以跳跃的最大长度。
判断你是否能到达数组的最后一个位置。
样例
A = [2,3,1,1,4],返回 true.
A = [3,2,1,0,4],返回 false.
分析:遍历一遍,记录可走的点可以达到的最远点
代码:
class Solution { public: /** * @param A: A list of integers * @return: The boolean answer */ bool canJump(vector<int> A) { // write you code here int maxN = 0; int i = 0; while(i<=maxN) { maxN = max(maxN,i+A[i]); i++; if(maxN>=A.size()-1) return true; } return false; } };
相关文章推荐
- 跳跃游戏-LintCode
- LintCode 116-跳跃游戏
- lintcode: 跳跃游戏 II
- [Lintcode] #116 跳跃游戏
- lintcode ----跳跃游戏
- lintcode : 跳跃游戏
- lintcode--跳跃游戏
- 跳跃游戏 II-LintCode
- [Lintcode]Jump Game跳跃游戏
- LintCode 跳跃游戏 解答
- lintcode:跳跃游戏——解析
- lintcode-跳跃游戏II-117
- [Lintcode]跳跃游戏 II
- lintcode 跳跃游戏(116)
- [LintCode] 跳跃游戏
- lintcode-116-跳跃游戏
- lintcode-跳跃游戏-116
- 手把手教你写跳跃类游戏(3)
- 计蒜客 跳跃游戏
- 手把手教你写跳跃类游戏——最终版本及所有源码!