[Leetcode] 55. Jump Game
2015-03-22 01:40
513 查看
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.
public class Solution { public boolean canJump(int[] A) { if(A == null || A.length == 0) return false; int step = A[0]; for(int i = 1; i < A.length; i++){ step--; if(step < 0) return false; step = Math.max(step, A[i]); } return true; } }
相关文章推荐
- LeetCode 55. Jump Game
- 【C++】【LeetCode】55. Jump Game
- LeetCode 55. Jump Game
- Leetcode 55. Jump Game
- Leetcode题解:55. Jump Game
- Jump Game 的三种思路 - leetcode 55. Jump Game
- Leetcode-55. Jump Game
- LeetCode 55. Jump Game
- 算法分析与设计——LeetCode:55. Jump Game
- Leetcode 55. Jump Game
- 个人记录-LeetCode 55. Jump Game
- LeetCode 55. Jump Game
- leetcode 55. Jump Game
- LeetCode 55. Jump Game
- leetcode题解-55. Jump Game && 56. Merge Intervals
- 【LeetCode】55. Jump Game
- [LeetCode]--55. Jump Game
- leetcode 55. Jump Game
- leetcode.array--55. Jump Game
- LeetCode 55. Jump Game