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. linux命令学习-2

    1. 对于已经在前台执行的命令,可以重新放到后台执行,首先按ctrl+z暂停已经运行的进程,然后使用jobs查看进程编号n:2. bg命令将停止的作业放到后台运行 bg %n3. kill -9 XX ...

  2. 使用JavaConfig方式-Spring 基础学习

    在Spring的使用中,大量采用xml方式配置类之间的关系太过于繁琐(个人这么认为),而在学习了Spring4后发下使用JavaConfig方式来配置这些关系会更加的简单明了. 测试环境 1. Apa ...

  3. loj2043 「CQOI2016」K 远点对

    k-d tree 裸题------ #include <algorithm> #include <iostream> #include <cstdio> using ...

  4. WCF,WebServices,WebApi区别

    http://www.cnblogs.com/hetring/p/4493137.html

  5. IOS开发---菜鸟学习之路--(十二)-利用ASIHTTPRequest进行异步获取数据

    想要实现异步获取的话我这边了解过来有两个非常简单的方式 一个是利用ASIHTTPRequest来实现异步获取数据 另一个则是利用MBProgressHUD来实现异步获取数据 本章就先来讲解如何利用AS ...

  6. leetcode 【 Find Minimum in Rotated Sorted Array II 】python 实现

    题目: Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? W ...

  7. 判断 js 数组是否为 empty

    function isEmpty(obj) { for(var key in obj) { if(obj.hasOwnProperty(key)) return false; } return tru ...

  8. [oldboy-django][2深入django]班级管理(Form)--查看

    1 需求:django实现班级管理:查看(分页): 数据库采用django自带的sqlite3 2 数据库表创建 from django.db import models class Classes( ...

  9. Ant 概念

    Ant的概念 可能有些读者并不连接什么是Ant以及入可使用它,但只要使用通过Linux系统得读者,应该知道make这个命令.当编译Linux内核及一些软件的源程序时,经常要用这个命令.Make命令其实 ...

  10. PAT1038(两个运行超时 未解决

    # include<iostream> # include<algorithm> using namespace std; int jishu(int a[],int N,in ...