[LeetCode]Jump Game
2017-02-23 10:59
309 查看
https://leetcode.com/problems/jump-game/?tab=Description
数组表示青蛙下次能跳的距离,问能否跳到结尾
max记录目前能跳的最远位置,如果当前遍历位置已经跳不到,就永远跳不到结尾了
public class Solution {
public boolean canJump(int[] nums) {
int max = 0;
for (int i = 0; i < nums.length; i++) {
if (i > max) {
return false;
}
max = Math.max(i + nums[i], max);
}
return true;
}
}
数组表示青蛙下次能跳的距离,问能否跳到结尾
max记录目前能跳的最远位置,如果当前遍历位置已经跳不到,就永远跳不到结尾了
public class Solution {
public boolean canJump(int[] nums) {
int max = 0;
for (int i = 0; i < nums.length; i++) {
if (i > max) {
return false;
}
max = Math.max(i + nums[i], max);
}
return true;
}
}
相关文章推荐
- 【LeetCode】55. Jump Game
- LeetCode - Jump Game
- 【Leetcode】45,55 Jump game
- Leetcode Jump Game
- LeetCode_55---Jump Game
- [LeetCode]Jump Game
- [leetcode]55. Jump Game ,C++/PYTHON实现,medium难度
- [LeetCode]Jump Game
- [LeetCode] Jump Game
- 【LeetCode】Jump Game 解题报告
- leetcode: Jump Game--python
- Leetcode: Jump Game
- [leetcode题后感]Jump Game
- leetcode笔记:Jump Game
- LeetCode 55 Jump Game
- [Leetcode] Jump Game
- LeetCode 55 Jump Game(Python 实现及详解)
- leetcode 055 —— Jump Game
- LeetCode- Jump game
- LeetCode: Jump Game