[leetcode] Jump Game
2015-06-28 21:22
375 查看
From : https://leetcode.com/problems/jump-game/
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 =
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.
class Solution { public: bool canJump(vector<int>& nums) { int end = 0; for(int i=0, last=nums.size()-1; i<=last; i++) { if(end >= last) return true; if(i+nums[i] > end) end=i+nums[i]; if(i == end && nums[i]==0) return false; } return false; } };
相关文章推荐
- gradle运行java main
- 玩转oracle学习第七天
- Java CountDownLatch Example(转)
- 无IDE时编译和运行Java
- 《Java程序设计》第16周周五:数据库连接与随机数的使用
- springmvc和servlet在上传和下载文件(保持文件夹和存储数据库Blob两种方式)
- Objective-C 快速入门--基础(三)
- 进程互斥(二)Dekker算法
- 玩转oracle学习第六天
- gcc vim c操作命令
- spring set注入
- [STL]C++中placement new操作符(经典)
- 剑指Offer--面试题29:数组中出现超过一半的数字
- [每日刷题(2015/6/27)]在一个分布式银行系统中,你如何测试一台ATM机?
- >输入子系统层次结构
- 文章标题
- 玩转oracle学习第五天
- How to use CyclicBarrier in Java - Concurrency Tutorail(转)
- 莫名其妙的Parse error: syntax error, unexpected $end 分类: php相关 2008-12-17 20:25 7086人阅读 评论(3) 收藏 举报 phpg
- CAS实现SSO(单点登录)原理