[LeetCode55]Jump Game
2016-04-18 20:58
441 查看
题目:
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
For example:
A =
A =
分类:Array Greedy
代码:
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
For example:
A =
[2,3,1,1,4], return
true.
A =
[3,2,1,0,4], return
false.
分类:Array Greedy
代码:
class Solution { public: bool canJump(vector<int>& nums) { int dis = 0; for(int i = 0; i <= dis; ++i) { dis = max(dis, i + nums[i]); if(dis >= nums.size()-1) return true; } return false; } };
相关文章推荐
- Codeforces Round #347 (Div.2)_A. Complicated GCD
- 《鬼谷子的局2》—— 读后总结
- mysql对GIS空间数据的支持,包括创建空间索引
- 程序员必备的代码审查(Code Review)清单【转载】
- PAT Have Fun with Numbers
- KMP算法详解
- [图文]我的bower使用之旅
- Verilog中一个字节比较器成熟的测试模型
- 实现一个函数,可以左旋字符串中K个字符
- TI双核处理器ARM+DSP如何实现协同工作
- Android 五大布局
- ue4 Skeletal Mesh编辑器
- 第七周学习进度表
- 用WebDriver实现基于jira过滤器视图的统计自动化
- 牧场主与猎户的故事
- iOS设置图片最大尺寸
- 微信扫码支付第一种场景(先生成产品二维码,用户扫码生成交易)JAVA开发总结
- 查找之三:二叉排序树(续)
- UIButton 的edgeInsets研究
- 大根堆 - max heapify