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 ...
随机推荐
- Django配置邮箱登录
1.settings下配置 # AUTH 方法(支持邮箱登录) AUTHENTICATION_BACKENDS = ('users.views.CustomBackend',) 2.views下逻辑如 ...
- PSTR、LPSTR等宏原型
1.首先介绍char.wchar_t ,宽字符wchar_t和窄字符char. 窄字符char了,大家都很清楚,就是8bit表示的byte,长度固定.char字符只能表示ASII码表中的256个字符, ...
- [Poj3281]Dining(最大流)
Description 有n头牛,f种食物,d种饮料,每头牛有nf种喜欢的食物,nd种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种食物了,饮料也同理,问最多有多少头牛可以吃到它喜欢的 ...
- Tricky Sum
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all po ...
- GIt-恢复进度
继续暂存区未完成的实践 经过了前面的实践,现在DEMO版本库应该处于master分支上,看看是不是这样. $ cd /path/to/my/workspace/demo $ git status -s ...
- 通过js date对象获取各种开始结束日期的示例
有时候做一些任务计划的功能时候,需要提供一个开始时间或者结束时间,比如本周结束,本月结束,今天结束等等,因此,我参考网上的资料把相关的实现为一个项目: gitee: https://gitee.com ...
- 68、TSPL指令集(标签打印机)
0.开发者pdf.sdk等资料详见: http://download.csdn.net/detail/kunyashaw/9376694 1.测试代码 包含文字打印.条形码打印.二维码打印 packa ...
- leetcode 【 Majority Element 】python 实现
题目: Given an array of size n, find the majority element. The majority element is the element that ap ...
- 图说不为人知的IT传奇故事-3-硅谷DNA创造者HP
此系列文章为“图说不为人知的IT传奇故事”,各位大忙人可以在一分钟甚至几秒内了解把握整个内容,真可谓“大忙人的福利”呀!!希望各位IT界的朋友在钻研技术的同时,也能在文学.历史上有所把握.了解这些故事 ...
- 对CRC32的小结加上bugku一道题目:好多压缩包
CRC32就是校验值,一般来说不同的文件校验值不一样,所以我们可以挨个爆破,当然这是在文件比较小的时候.下面是几种情形. 1. 我新建了一个flag.txt文档,里面是我的生日20180818 然后我 ...