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. GBK UTF8 GB2132

    GBK就是在保存你的帖子的时候,一个汉字占用两个字节,外国人看会出现乱码,为此我中华为自己汉字编码而形成之解决方案. UTF8就是在保存你的帖子的时候,一个汉字占用3个字节.但是外国人看的话不会乱码. ...

  2. MongDB之各种查询操作

    接口IMongDaoFind: package com.net.test.mongdb.dao; public interface IMongDaoFind { public void findUse ...

  3. Python中的正则

    regex_lst = [ ('字符组',), ('非打印字符',), ('特殊字符',), ('定位符',), ('限定符',), ('re模块',), ('分组命名',), ('或匹配',), ( ...

  4. Cube HDU - 1220(思维)

    Cowl is good at solving math problems. One day a friend asked him such a question: You are given a c ...

  5. 读《深入理解jvm虚拟机》之长期存活对象进入老年代,有感!!!!

    关于这一段代码 有几个不是让人很理解的地方,我一一说来. 1.Desired survivor size 524288 bytes 关于这个512KB空间是怎么来的,JVM有这样一个参数: -XX:T ...

  6. Asp.net自定义控件开发任我行(3)-Render

    摘要 上一篇我们讲到了自定义标签TagPrefix用法,此篇我们来讲一下控件的呈现,主要是呈现下拉框 内容 呈现的方法有,Render,RenderControl,RenderChildren,这三个 ...

  7. python 使用 vscode 调试

    vscode安装python扩展,在vscode扩展管理器中搜索pyhon, 排名第一的就是我们需要下载的包—python.点击安装后重载窗体 点击调试–打开launch.json的按钮(那个小齿轮的 ...

  8. c++ 吕凤翥 第五章 类对象一

    一   类的声明和实现 1. class tdate   //声明部分 { public: void setdate(int y,int m,int d); int isleapyear(); voi ...

  9. FastDFS的安装(复制自己用)

    FastDFS 安装及使用 FastDFS 安装及使用 2012-11-17 13:10:31|  分类: Linux|举报|字号 订阅     Google了一下,流行的开源分布式文件系统有很多,介 ...

  10. 【bzoj3944/bzoj4805】Sum/欧拉函数求和 杜教筛

    bzoj3944 题目描述 输入 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 输出 一共T行,每行两个用空格分隔的数ans1,ans2 样例输 ...