LeetCode *** 55. Jump Game
2016-04-19 20:19
465 查看
题目:
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 far=-1,size=nums.size(); for(int i=0;i<size;++i){ if(nums[i]+i>far)far=nums[i]+i; if(far>=size-1)return true; if(nums[i]==0&&far<=i)return false; } return true; } };
相关文章推荐
- C# struct的陷阱:无法修改“...”的返回值,因为它不是变量
- 输出时,自动加上行号
- Set集合
- 数据结构学习安排
- [经典] 回文问题(一)
- android开发 用线程进行耗时操作,统一处理 第二版
- 深入理解synchronized
- Android官方开发文档Training系列课程中文版:调用相机之控制相机
- ansible的安装部署及简单应用
- 插入排序(InsertionSort)
- 剑指offer之找没有重复出现的数字
- 多表连接查询
- ansible的安装部署及简单应用
- 站立会议01
- 配置visual studio code进行asp.net core rc2的开发
- 使用GoodFeaturesToTrack进行关键点检测---29
- 深入理解Lock
- [leetcode] 341. Flatten Nested List Iterator
- 51nod 1060 最复杂的数(反素数)
- javaScript数组循环删除