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 for LeetCode 045 Jump Game II把返回值改为boolean即可,JAVA实现如下:

 static public boolean canJump(int[] nums) {
int index=0,maxStepIndex=0,start=0;
while(nums.length>1){
for(int i=start;i<=index+nums[index];i++){
if(i+nums[i]>=nums.length-1)
return true;
if(i+nums[i]>=nums[maxStepIndex]+maxStepIndex)
maxStepIndex=i;
}
start=index+nums[index]+1;
if(index==maxStepIndex)
return false;
index=maxStepIndex;
}
return true;
}

Java for LeetCode 055 Jump Game的更多相关文章

  1. Java for LeetCode 045 Jump Game II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  2. [LeetCode] 45. Jump Game II 跳跃游戏 II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  3. Java for LeetCode 216 Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  4. Java for LeetCode 214 Shortest Palindrome

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  5. Java for LeetCode 212 Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  6. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

  7. Java for LeetCode 210 Course Schedule II

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  8. Java for LeetCode 200 Number of Islands

    Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...

  9. Java for LeetCode 188 Best Time to Buy and Sell Stock IV【HARD】

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

随机推荐

  1. 使用FMDB事务批量更新数据库

    今天比较闲看到大家在群里讨论关于数据库操作的问题,其中谈到了“事务”这个词,坦白讲虽然作为计算机专业的学生,在上学的时候确实知道存储过程.触发器.事务等等这些名词的概念,但是由于毕业后从事的不是服务器 ...

  2. 10.Android之ProgressDialog进度对话框学习

    APP应用中经常会下载某些东西,这里面有涉及到进度对话框,今天来学习下. 首先,布局里放进两个按钮,点击一个显示条形进度条,另一个显示圆形进度条.代码如下: <?xml version=&quo ...

  3. Spring JdbcTemplate 的使用与学习

    JDBCTemplate 是SPRING 框架自带的一种对sql 语句查询的封装 ,封装非常完善,虽然与Hibernate比起来有一点麻烦,但是学号JDBCTemplate可以让我们用Spirngmv ...

  4. AU3学习资源

    AU3中文站:http://www.autoitx.com/

  5. dijkstra,SPFA,Floyd求最短路

    Dijkstra: 裸的算法,O(n^2),使用邻接矩阵: 算法思想: 定义两个集合,一开始集合1只有一个源点,集合2有剩下的点. STEP1:在集合2中找一个到源点距离最近的顶点k:min{d[k] ...

  6. HDU2888 Check Corners

    Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 ...

  7. POJ2253 Frogger

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34865   Accepted: 11192 Descrip ...

  8. Docker Architecture、Docker Usage

    目录 . 引言 - 为什么要有Docker技术 . Docker简介 . Docker安装.部署.使用 . Docker安全 . Docker底层实现 . Docker网络配置 . Dockerfil ...

  9. (转)google Java编程风格中文版

    转:http://www.hawstein.com/posts/google-java-style.html 目录 前言 源文件基础 源文件结构 格式 命名约定 编程实践 Javadoc 后记 前言 ...

  10. PHP中应用GD2函数在图像上添加文字

    <?php header("Content-type:text/html;charset=utf-8"); header("Content-type:image/g ...