LeetCode 55. Jump Game
2016-04-18 12:08
447 查看
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 =
This idea actually is from someone else. But it is so neat! In order to reach the end, we only need to calculate the maxStep we can go within current reachable scope....
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.
This idea actually is from someone else. But it is so neat! In order to reach the end, we only need to calculate the maxStep we can go within current reachable scope....
bool canJump(vector<int>& nums) { int maxStep = 0; int i = 0; while(i < nums.size() && i <= maxStep) { maxStep = max(nums[i] + i, maxStep); i++; } return maxStep >= nums.size() - 1; }
相关文章推荐
- linux ssh上传和下载
- Service Broker完成实例之间的会话详细解读
- 博客
- CocoaPods安装和使用教程
- python模块:re模块
- python模块:re模块
- PAM登录代码
- SSL协议详解
- simpleOS 1.0
- SQL语句oracle中如何插入Date类型的数据
- Get请求出现乱码的解决方案
- 各种view
- oracle 手工建库
- AngularJS入门教程之AngularJS指令
- python脚本监控redis制作zabbix模板
- CentOS6下ssh无法连接
- java.io.filenotfoundexception: ... .jar
- 瀑布流怎么理解和实现的
- c++类的拷贝构造函数、隐式转换、重载的赋值操作符的一些分析和实例
- theano tutorial(一)