[LeetCode55]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 = [2,3,1,1,4], return true.
A = [3,2,1,0,4], return false.
分类:Array Greedy
代码:
class Solution {
public:
bool canJump(vector<int>& nums) {
int dis = ;
for(int i = ; i <= dis; ++i)
{
dis = max(dis, i + nums[i]);
if(dis >= nums.size()-)
return true;
}
return false;
}
};
[LeetCode55]Jump Game的更多相关文章
- [array] leetcode-55. Jump Game - Medium
leetcode-55. Jump Game - Medium descrition Given an array of non-negative integers, you are initiall ...
- leetcode55—Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- leetcode-55. Jump Game · Array
题面 这个题面挺简单的,不难理解.给定非负数组,每一个元素都可以看作是一个格子.其中每一个元素值都代表当前可跳跃的格子数,判断是否可以到达最后的格子. 样例 Input: [2,3,1,1,4] Ou ...
- Leetcode55. Jump Game跳跃游戏
给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: true ...
- [Swift]LeetCode55. 跳跃游戏 | Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] Frog Jump 青蛙过河
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- [LeetCode] Jump Game 跳跃游戏
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] Jump Game II 跳跃游戏之二
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Leetcode 45. Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
随机推荐
- TRIZ系列-创新原理-29-气动或液压结构原理
气动或液压结构原理的详细表述例如以下:1)用气态或液态部件替代固体部件.能够用空气或者水,也能够用气垫或水垫,使这些部件膨胀.这条原理符合系统的动态性进化法则-柔性化.在改造系统时,我们能够尝试将系统 ...
- Conexant声卡实现内录功能(win7)
Conexant声卡本身没有立体声混音设备可选,所以我们采用virtual audio device,实现内录功能. [1]下载virtual audio device.下载地址:http://dow ...
- spark的action和transformations汇集
汇总了Spark支持的Transformations 和Actions 用于备忘! 參考 http://spark.apache.org/docs/latest/programming-guide.h ...
- POJ 2365 Rope(水题)
[题意简述]:给出我们钉子个数与半径,让我们求出缠绕在钉子上的绳子有多长. [分析]:从题目中我们能够看出,绳子长度的和等于每两个钉子的距离的和加上接触在钉子上的绳子的长度,不难发现这部分长度事实上就 ...
- A Game of Thrones(10) - Jon
Jon climbed the steps slowly, trying not to think that this might be the last time ever. Ghost padde ...
- poj2096(概率dp)
题目连接:http://poj.org/problem?id=2096 题意:一个程序有m个子系统,要找出n种bug,某人一天找n种bug中的一种,求出他找出n种bug并且每个子系统中都有bug的天数 ...
- ubuntu下使用自带的openJDK查看java源码
如题 Ubuntu自带的OpenJDK仅仅有jre环境,不提供源代码,所以我们还是须要去下载. JDK6:http://download.java.net/openjdk/jdk6/ JDK7:htt ...
- 每天一个JavaScript实例-html5拖拽
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- atitit查询表改动表字段没反应--解锁锁定的表
atitit查询表改动表字段没反应--解锁锁定的表 查询表改动表字段没反应 要是使用gui 没反应,最好使用cmd 方式,不卉不个gui 锁上.. ALTER TABLE t_mb_awardweix ...
- VMware workstation 安装错误提示1021解决方法
Failed to create the requested registry key Key: Installer Error: 1021 解决方法:删除注册表--HKEY_LOCAL_MACHIN ...