题目:非负数的数组,每个数组元素代表这你能最大跨越多少步,初始在0的位置,问,能不能正好调到数组的最后一位!

https://leetcode.com/problems/jump-game/#/description

思路1:从尾部记录每个元素能不能到达末尾,算法复杂度O(n*n)【当时想出这个算法,还自以为不错,但是leetcode说算法超时呀,被分分钟教做人】

思路2:对这整个数组中的数据结构深刻的理解!(参考:http://blog.csdn.net/linhuanmars/article/details/21354751),首先明白一个问题:只要数组中不含有0,那么这个数组肯定是可以跳过去的!==> 得到一个结论是:只要能跳到数组外面,那么我们就一定能够跳到最后一个位置!所以就看下从数组中第一个位置开始,最远能跳到哪里就好了!之前的疑惑包括:1)怎么确定从第一个下标开始能跑多远呢?难道我们不需要递归这一路上所有的步数可能吗?万一路上遇到一个0,那不直接盼死刑,我们就得退一步,然后求少走的这条路啊!这就是之前的症结所在,是一种线性思维!于是有了参考网页中的算法:我们同时记录全局最优局部最优。全局最优,实时更新,全局最优之间的每一个节点,目前都是可以到达的知道吗!呃呃呃,需要分析的东西好多,并且这些东西都是解题思路的关键呢!那么只要在这个范围之内的节点能够到达更远的地方,那么全局的最远的点就应该被更新!

答案

https://github.com/honpey/codebox/blob/master/leetcode/array/p55.cpp

算法(5)Jump Game的更多相关文章

  1. [leetcode.com]算法题目 - Jump Game

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

  2. JPS/JPS+ 寻路算法

    目录 概念 强迫邻居(Forced Neighbour) 跳点(Jump Point) JPS 寻路算法(Jump Point Search) 实现原理 示例过程 JPS+(Jump Point Se ...

  3. Jump Game I&&II——入门级贪心算法

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

  4. jump game(贪心算法)

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

  5. 经典算法——Jump Game(II)

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

  6. (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)

    --------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...

  7. [原创]基于rsync算法的目的性改进-RexSync

    rsync是一种文件差异传输的算法,特点是高效且相似块识别率较高.具体算法这边就不赘述,网上很多,官方文档也描述的很清楚. rsync提高文件比对效率的一个核心算法之一就是rolling checks ...

  8. LeetCode 笔记系列13 Jump Game II [去掉不必要的计算]

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

  9. Leetcode jump Game

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

随机推荐

  1. 详解Linux运维工程师

    运维工程师是从一个呆逼进化为苦逼再成长为牛逼的过程,前提在于你要能忍能干能拼,还要具有敏锐的嗅觉感知前方潮流变化.如:今年大数据,人工智能比较火……(相对表示就是 Python 比较火) 之前写过运维 ...

  2. 配置vue-devtools调试工具

    1. 通过 Git 克隆项目到本地 git clone https://github.com/vuejs/vue-devtools.git 2. Git 进入到 vue-devtools 所在目录,然 ...

  3. 【vlan之四种方式链路认证组网]

    ---恢复内容开始--- 根据项目需求,搭建好如下拓扑图: 在[sysname]下配置给予协议的vlan vlan 1#vlan 10 protocol-vlan 0 ipv4#vlan 20 pro ...

  4. 微信程序跳转到页面底部 scroll-view

    wx.createSelectorQuery().select('#j_page').boundingClientRect(function (rect) { wx.pageScrollTo({ sc ...

  5. Json格式化时间

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")@JsonFormat(timezone = "GMT+8", ...

  6. 2002: [Hnoi2010]Bounce 弹飞绵羊

    2002: [Hnoi2010]Bounce 弹飞绵羊 https://www.lydsy.com/JudgeOnline/problem.php?id=2002 分析: 绵羊在弹飞的路径中相当于一棵 ...

  7. 关于==和equals()方法&Java中string与char如何转换&String,StringBuffer

    1.对于基本数据类型,可以直接使用==和!=进行内容比较 如:int x=30;        int y=30;         x==y;  //true 基本数据类型 简单类型(基本类型) bo ...

  8. OrCAD设置原理图页面大小

    1. 右键要修改的原理图文件 2. 选择适合的尺寸

  9. dubbo心跳机制 (1)

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. dubbo的心跳机制: 目的:检测provider与consumer之间的connection连接是不是还连 ...

  10. 为什么在默认情况下无法修改被block捕获的变量? __block都做了什么?

    默认情况下,block里面的变量,拷贝进去的是变量的值,而不是指向变量的内存的指针.使用__block修饰后的变量,拷贝到block里面的就是指向变量的指针,所以我们就可以修改变量的值.