【LeetCode】55. Jump Game
2018-03-15 17:52
453 查看
题目描述
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.
代码如下
class Solution { public boolean canJump(int[] nums) { if(nums==null||nums.length==0) return true; int reachable = 0; for(int i=0;i<nums.length;i++) { if(i>reachable) return false; reachable=Math.max(reachable,nums[i]+i); } return true; } }
相关文章推荐
- leetcode 55. Jump Game(C语言,跳数,递归思想,两种解法)20
- [LeetCode] 55. Jump Game 跳跃游戏
- Leetcode题解-55. Jump Game
- LeetCode 55. Jump Game|贪心算法
- LeetCode 55. Jump Game and 45. Jump Game II 题解
- [leetcode]55. Jump Game 贪心
- LeetCode 55. Jump Game (跳跃游戏)
- (Java)LeetCode-55. Jump Game
- [LeetCode]55.Jump Game
- LeetCode 55. Jump Game 解题报告
- [array] leetcode-55. Jump Game - Medium
- leetcode解题之45. Jump Game II&55. Jump Game java (跳跃游戏)
- LeetCode 55. Jump Game
- leetcode 55. Jump Game [贪心]
- [leetcode 55. Jump Game]week 7
- [leetcode]55. Jump Game(Java)
- LeetCode 55. Jump Game(跳格子)
- 【LeetCode】55. Jump Game (Medium)
- Leetcode 55. Jump Game (Medium) (cpp)
- Leetcode(W6):55. Jump Game