https://oj.leetcode.com/problems/jump-game/

从0开始,根据每一位上存的数值往前跳。

这道题给想复杂了。。。

记录当前位置 pos,记录可以调到的最远达位置为far,并随时更新它

如果 far >= n - 1 则相当于调到末尾了,在此过程中 pos <= far

class Solution {
public:
bool canJump(int A[], int n) {
if(n==)
return false; if(n==)
return true; int far = A[] + ;
int current = ;
while(current<=far &&current<n)
{
if(far >= n - )
return true;
if(far<A[current] + current)
far = A[current] + current;
current++;
} return false;
}
};

LeetCode OJ-- Jump Game的更多相关文章

  1. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  2. Java for LeetCode 055 Jump Game

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

  3. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  4. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  5. LeetCode OJ学习

    一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...

  6. LeetCode OJ 297. Serialize and Deserialize Binary Tree

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  7. [LeetCode] 45. Jump Game II_ Hard tag: Dynamic Programming

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

  8. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

  9. [leetcode]45. Jump Game II青蛙跳(跳到终点最小步数)

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

  10. LeetCode OJ 之 Maximal Square (最大的正方形)

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

随机推荐

  1. docker时区正常,但java获得的时间早了8小时解决方法

    我解决容器时区的方法是挂载宿主机的/etc/localtime 到容器的/etc/localtime,这时输入date命令容器时区显示正常,但是跑在容器中的java项目取到的时间却早了8小时. 查阅相 ...

  2. 动态规划:HDU1069-Monkey and Banana

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. Fiddler用AutoResponder实现app升级异步更新

    先说一下我自己理解的异步更新:用app异步升级举例,app是否升级的检查是在启动app时访问服务器的,把app本地的最新版本号与服务器端的最新版本号做对比,假如不一致,则提示升级.但本次已经打开使用a ...

  4. Android 自定义debug.keystore

    场景分析: 有时候,我们要使用第三方的服务,需要提供自己的包名以及keystore的sha1值,比如微信支付,百度地图,都需要包名和keystore的sha1值作为唯一标识.这时候我们测试的时候,如果 ...

  5. 组装需要的json数据格式

    在实际项目中有时候会遇到一些有特殊要求的控件,比如easyui-combogrid,加载的并不是常见的json格式,这里我遇到过需要加载类似省市县这种三级数据格式.最后也是从别人的博客中学到的如何组装 ...

  6. laravel5.2总结--redis使用

    一切的前提都是已经安装好了redis服务器,并且能启动(我只总结了mac的安装方法:传送门) 我自己使用的是mac系统,有个教程可以参考下,传送门: 1.安装PHP PRedis 1>PRedi ...

  7. CTF 两道web整数溢出题目(猫咪银行和ltshop)

    ①猫咪银行: (2018中科大hackgame) 一开始给十个CTB,而flag需要20个CTB,我们需要理财赚够20个. 理财是只能买入TDSU才可以获得收益.我们先上来直接把CTB全部换成TDSU ...

  8. day02_04.算算多少人

    第四题 算算有多少人? 第二题的升级版,看看你能不能做出来 利用你的编程思想去看这道题目,记住不要放过题目的每一个小细节 题目:操场上100多人排队,3人一组多1人,4个一组多2人,5人一组多3人,共 ...

  9. 用户注册,登录API 接口

    Controer: <?php /** * @name UserController * @author pangee * @desc 用户控制器 */ class UserController ...

  10. C#知识点<2>

    1. ? : 运算符(真2假3) 我们已经在前面的章节中讲解了 条件运算符 ? :,可以用来替代 if...else 语句.它的一般形式如下: Exp1 ? Exp2 : Exp3; 其中,Exp1. ...