[LeetCode]Jump Game
2013-12-19 14:11
423 查看
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 =
A =
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.
class Solution { public: bool canJump(int A[], int n) { int step=A[0]; for(int i=1;i<n;i++) { if(step==0) return false; step--; step=max(step,A[i]); } return true; } };
相关文章推荐
- 动态规划小结 - 一维动态规划 - 时间复杂度 O(n),题 [LeetCode] Jump Game,Decode Ways
- leetcode[55]Jump Game
- [LeetCode] 55. Jump Game
- Leetcode题解-55. Jump Game
- leetcode Jump Game ||
- 算法分析与设计课程(9):【leetcode】Jump Game
- [Leetcode] Jump Game
- LeetCode 55 - Jump Game
- [leetcode.com]算法题目 - Jump Game
- Leetcode:Jump Game
- leetcode 刷题之路 54 Jump Game
- LeetCode: Jump Game
- [LeetCode]题解(python):055-Jump Game
- LeetCode (Jump Game)
- leetcode55. Jump Game (贪心)
- LeetCode 055 Jump Game
- Leetcode--jump game (最大跳)
- 【Leetcode】Jump Game (DP)
- [leetcode]Jump Game
- [C++]LeetCode: 103 Jump Game (局部最优和全局最优法)