Jump Game
来源:互联网 发布:php网络爬虫教程 编辑:程序博客网 时间:2024/06/06 09:25
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.
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) { if(nums.empty()) //数组为空 return false; int curarrive=0; int i=0; while(i<=curarrive&&curarrive<nums.size()) { if(i+nums[i]>curarrive) curarrive=i+nums[i]; i++; } return curarrive>=nums.size()-1; }};
0 0
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- HDU 2844-Coins(多重背包)
- javadoc解决中文乱码问题
- iOS网络4——Reachability检测网络状态
- Swift 项目中可能用到的第三方框架
- js 正则表达式 匹配括号内的内容
- Jump Game
- C/C++中函数指针
- Redis快速入门:Key-Value存储系统简介
- php 简单实现 图片压缩
- RecyclerView添加Header的正确方式
- IDEA 报错These modules have been removed from Maven stucture
- 在github看到好的项目了,然后呢?(安卓篇)
- Hadoop API 使用介绍
- 使用通知选择城市