题目:

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的更多相关文章

  1. [array] leetcode-55. Jump Game - Medium

    leetcode-55. Jump Game - Medium descrition Given an array of non-negative integers, you are initiall ...

  2. leetcode55—Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  3. leetcode-55. Jump Game · Array

    题面 这个题面挺简单的,不难理解.给定非负数组,每一个元素都可以看作是一个格子.其中每一个元素值都代表当前可跳跃的格子数,判断是否可以到达最后的格子. 样例 Input: [2,3,1,1,4] Ou ...

  4. Leetcode55. Jump Game跳跃游戏

    给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: true ...

  5. [Swift]LeetCode55. 跳跃游戏 | Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  6. [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 ...

  7. [LeetCode] Jump Game 跳跃游戏

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. [LeetCode] Jump Game II 跳跃游戏之二

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  9. Leetcode 45. Jump Game II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

随机推荐

  1. 再读TCP/IP网络7层协议

    随着工作的深入,每次读这7层协议,每次都有不同的理解. 分层名                                                               分层号   ...

  2. Maven POM入门

    Super POM(project object model) Maven内置了一个默认的POM(不在项目中,因此不可见),每一个project都会继承自这个默认的POM,因此叫Super POM.除 ...

  3. Http协议学习总结(转)

    因为项目中很多地方都与Http协议有关,零散的了解了一下Http协议,但是没有系统的学习过. 今天根据网上其他同学的整理,加上我的一些经验,我也整理了一份.当做学习记录吧. 一.什么是HTTP协议 H ...

  4. hdu4586(概率、期望)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4586 题意:有一个色子,n面,每面有个分值a[i],其中有m面比较特殊,当该面出现时,可以再投一次.求 ...

  5. POJ 1703:Find them, Catch them(并用正确的设置检查)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30702   Accepted: ...

  6. Android LCD(三):Samsung LCD接口篇

    关键词:android LCD控制器 Framebuffer PWM  平台信息: 内核:linux2.6/linux3.0 系统:android/android4.0  平台:samsung exy ...

  7. Linux iptables简单配置

    #!/bin/sh#modprobe ipt_MASQUERADEmodprobe ip_conntrack_ftpmodprobe ip_nat_ftpiptables -Fiptables -t ...

  8. A Game of Thrones(6) - Catelyn

    Of all the rooms in Winterfell’s Great Keep, Catelyn’s bedchambers(['bedtʃeɪmbə]卧室,寝室) were the hott ...

  9. hdu1025 Constructing Roads In JGShining&#39;s Kingdom (nlogn的LIS)

    题目链接 第一次写nlogn复杂度的LIS,纪念一下. 题目意思是说.有两条平行线.两条平行线都有n个城市,都是从左到右标记为1--n,一条线上是富有城市,一个是贫穷城市.输入n.接下来有n行,p,r ...

  10. HDU5015 233 Matrix(矩阵高速幂)

    HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...