LeetCode OJ-- Jump Game
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 &¤t<n)
{
if(far >= n - )
return true;
if(far<A[current] + current)
far = A[current] + current;
current++;
}
return false;
}
};
LeetCode OJ-- Jump Game的更多相关文章
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- Java for LeetCode 055 Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ学习
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...
- 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 ...
- [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 ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
- [leetcode]45. Jump Game II青蛙跳(跳到终点最小步数)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- 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 ...
随机推荐
- spark和MR比较
MapReduce: 分布式的计算框架 缺点:执行速度慢 IO瓶颈 ==> 磁盘IO 网络IO shuffle机制:数据需要输出到磁盘,而且每次shuffle都需要进行排序操作 框架的机制: 只 ...
- Python知识点入门笔记——特色数据类型(集合)
集合是一种不重复的无序集 集合用花括号来定义{} 集合和字典一样,里面的顺序是无序的,{1,2,3}和{3,2,1}是相等的 集合的元素不可重复,也就是说{1,2,2,3}是不存在的,应该写为{1,2 ...
- django之配置静态文件
# 别名 STATIC_URL = '/static/' # 配置静态文件,名字必须是STATICFILES_DIRS STATICFILES_DIRS = [ os.path.join(BASE_D ...
- iOS SDK中使用NSXMLParser解析XML(iphone网络篇三)
iOS SDK的NSXMLParser解析XML文档是事件驱动模式的,即采用SAX方式来解析XML格式文档.NSXMLParser在处理XML文档的过程中当遇到一些要素(元素.属性.CDATA块.评论 ...
- nowcoder N约数个数
n的约数个数 题目:t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数 数据:对于100%的数据,t <= 500 , 1 <= n <= 10000000000 ...
- vi a.sh ABCD
E: 无法定位软件包 ubuntu预装的是 vim tiny,安装vim full版本,可以解决 卸载vim-tiny: $ sudo apt-get remove vim-common 安装vim ...
- PowerShell批量启动/关闭Azure VM
备注:以下例子中出现的JohnsonWeb, JohnsonVm均是虚拟机的名称.在运行Powershell脚本之前,请导入您的订阅文件. 根据条件启动/关闭虚拟机,例如根据虚拟机名称,批量启动/关闭 ...
- MySQL基础7-分页查询
1.分页查询(MySQL特有的,oracle中没有) 栗子1: 每页最多3条记录:pageSize=3:第一页:SELECT * FROM product LIMIT 0,3第二页:SELECT * ...
- Algorithms(fourth edition)——无向图
1.设计图基本操作API 2.用什么数据结构来表示图并实现API 要求:(1)要预留足够空间 (2)实例方法实现要快 三个选择: 邻接矩阵:布尔矩阵,不满足条件一,而且无法表示平行边 边的数组:不满足 ...
- Dcgpofix
TechNet Library Windows Server Windows Server 2012 R2 and Windows Server 2012 Management and Tools C ...