开始刷leetcode day13:Jump Game
来源:互联网 发布:如何评价黄海冰 知乎 编辑:程序博客网 时间:2024/06/06 17:35
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
.
Java:
public class Solution {
public boolean canJump(int[] nums) {
if(nums.length == 0) return false;
int globalmax = 0;
for(int i=0; i<=globalmax && i<nums.length-1;i++)
{
globalmax = Math.max(i+nums[i],globalmax);
}
if(globalmax < nums.length-1) return false;
else return true;
}
}
注意 在forloop中还需要查看是否能到第i步
0 0
- 开始刷leetcode day13:Jump Game
- 开始刷leetcode day13:Find Peak Element
- LeetCode Jump Game && Jump GameII
- [LeetCode]Jump Game II、Jump Game
- 【LeetCode】Jump Game & Jump Game II
- leetcode Jump Game & Jump Game II
- leetcode之Jump Game && Jump Game II
- [leetcode]Jump Game &&Jump Game II
- 【LeetCode】Jump Game && Jump Game II
- [Leetcode]Jump Game && Jump Game II
- Leetcode之Jump Game & Jump Game II
- Jump Game 和Jump Game II---LeetCode
- LeetCode-Jump Game & Jump Game II
- 【Leetcode】【python】Jump Game/Jump Game II
- [leetcode刷题系列]Jump Game
- [leetcode刷题系列]Jump Game II
- LeetCode刷题笔录 Jump Game II
- LeetCode刷题笔录Jump Game
- jquery的html,text,val的区别
- 关于乱码的一点小小的心得
- 各种数字形状打印(嵌套for循环的应用)
- 送上最新鲜的互联网行业新闻-【2015-05-15】
- Factorial Trailing Zeroes
- 开始刷leetcode day13:Jump Game
- struts2+json+ajax 二级联动和json数据的页面展示
- zoj1203_Swordfish(最小生成树)
- 让ubuntu像windows那样显示网速,内存使用率
- hadoop
- 数据加密:什么是数据签名(What is a Digital Signature?)
- Prototype chain in JavaScript
- 海南分校第一期1班:张耀如奖学金文章更新连载1第一篇:
- Maven - Overview