题目:

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.

题解:

参考了http://fisherlei.blogspot.com/2012/12/leetcode-jump-game.html的代码

很巧妙的解法,代码很短,看着一眼就能看懂,但自己想不见得想的出来,好好品味一下

代码如下:

 1     public boolean canJump(int[] A) {  
 2             int maxCover = 0;  
 3             for(int start =0; start<= maxCover && start<A.length; start++)  
 4             {  
 5                  if(A[start]+start > maxCover)  
 6                       maxCover = A[start]+start;  
 7                  if(maxCover >= A.length-1) 
 8                     return true;  
 9             }  
             return false;  
        } 

Jump Game leetcode java的更多相关文章

  1. Jump Game - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Jump Game - LeetCode 注意点 解法 解法一:贪心算法,只关注能到达最远距离,如果能到达的最远距离大于结尾说明能到达,否则不能.并且如果 ...

  2. N-Queens II leetcode java

    题目: Follow up for N-Queens problem. Now, instead outputting board configurations, return the total n ...

  3. Jump Game II leetcode java

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

  4. 【Leetcode】经典的Jump Game in JAVA

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

  5. [LeetCode][Java] Jump Game II

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

  6. Regular Expression Matching leetcode java

    题目: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...

  7. Sqrt(int x) leetcode java

    Reference: http://blog.csdn.net/lbyxiafei/article/details/9375735  题目: Implement int sqrt(int x). Co ...

  8. ZigZag Conversion leetcode java

    题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...

  9. [LeetCode][Java]Candy@LeetCode

    Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...

随机推荐

  1. Tensorflow学习:(一)tensorflow框架基本概念

    一.Tensorflow基本概念 1.使用图(graphs)来表示计算任务,用于搭建神经网络的计算过程,但其只搭建网络,不计算 2.在被称之为会话(Session)的上下文(context)中执行图 ...

  2. jQuery 插件写法示例

    1.插件 taskStaticBar.js /**自定义任务进度条插件,用于发布任务单的显示进度 * 先初始化init() * 配置项type:1,任务发布方:type=2,生产方 * 然后传入sho ...

  3. PHP7.x新特性

    1.太空船操作符太空船操作符用于比较两个表达式. 当$a小于. 等于或大于$b时它分别返回-1. 0或1. // Integers echo 1 <=> 1; // 0 echo 1 &l ...

  4. c++ 时间相关的类型

    关于时间转换可以参考以下博客: https://www.jianshu.com/p/80de04b41c31 https://www.cnblogs.com/qicosmos/p/3642712.ht ...

  5. Python知识(6)--numpy做矩阵运算

    矩阵运算 论numpy中matrix 和 array的区别:http://blog.csdn.net/vincentlipan/article/details/20717163 matrix 和 ar ...

  6. C++反汇编-菱形继承

    学无止尽,积土成山,积水成渊-<C++反汇编与逆向分析技术揭秘> 读书笔记.马上就要出差了,回来后接着写吧. 一.概述 菱形继承是最复杂的对象结构,菱形结构会将单一继承与多重继承进行组合. ...

  7. BZOJ2831(小强的金字塔系列问题--区域整点数求法)

    题目:2831: 小强的金字塔 题意就是给出A,B,C,R,L,然后求 这里其实用到扩展欧几里德.(基本上参照clj的解题报告才理解的) 分析:我们先来分析一般情况: 这里我们假设A<C和B&l ...

  8. windows控制台程序——关于UNICODE字符的总结(转)

    前言:从Windows NT/2000开如,Windows系统已经是一个标准的UNICODE系统,系统内部所有字符串存储及操作均使用UNICODE编码.因此Win32 API都是UNICODE版本的, ...

  9. mysql内核 innodb存储引警(卷1)配书 用VS 2003 编绎 mysql-3.23.49 源代码

    作者网址:http://www.innomysql.net/ 1.旧版 mysql-3.23.49-win-src.zip 下载 (***络下载配书源代码)   或者  作者网盘  http://pa ...

  10. debian安装ibus中文输入法

    转载自:http://www.shunix.com/debian-ibus-chinese-470/ 以前在debian一直用scim,但是那个真的很不好用,现在用的是debian squeeze还是 ...