leetcode——55——Jump Game
2016-04-16 18:41
417 查看
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 =
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 size=nums.size(); if(size<=0){ return false; } int maxJump=-1; for(int i=0; i<size; i++){ if(nums[i]>maxJump){ maxJump=nums[i]; } if(maxJump>=size-i-1){ return true; } if(maxJump==0){ return false; } maxJump--; } return false; } };
相关文章推荐
- Lightoj-1258 Making Huge Palindromes(kmp||回文串)
- 合肥Android两天十面总结
- I2C通信代码分析1~2
- 利用Python爬虫,抓取淘宝MM照片
- 你的 Bitmap 究竟占多大内存?
- ENVI【遥感图像预处理之图像的几何校正】
- [android] 手机卫士手机实现短信指令获取位置
- 试除法计算最小的N个素数
- jdk卸载64位安装32位出现的问题
- 如何打印你的Log
- I2C总线的通信流程
- mysql学习笔记[1]
- 缓存策略
- 线性预测与Levinson-Durbin算法实现
- 通用工具类
- [codevs]1269匈牙利游戏
- hdu1128 Self Numbers--哈希表水题
- 面试题87:玛瑙项链
- linux知识整理
- python center, ljust, rjust