题目:

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. 向GridView的模板列绑定OnClientClick的函数时出现了奇怪的问题

    原文:向GridView的模板列绑定OnClientClick的函数时出现了奇怪的问题 GridView的一个模板列中的内容是按钮,需要实现以下的效果: GridView分页显示数据,点击编辑按钮(模 ...

  2. This application failed to start because it could not find or load the Qt platform plugin &quot;xcb&quot;.

    linux根据系统Qt5未安装编译的程序Qt在该系统下进行下面的错误会报: This application failed to start because it could not find or ...

  3. C库函数标准编程之fscanf()函数解读及其实验

    函数功能 fscanf()函数用于从参数stream的文件流中读取format格式的内容,然后存放到...所指定的变量中去.字符串以空格或换行符结束(实验1中会对它进一步说明) 函数格式 字符格式说明 ...

  4. Jersey框架三:Jersey对HTTPS的支持

    Jersey系列文章: Jersey框架一:Jersey RESTful WebService框架简介 Jersey框架二:Jersey对JSON的支持 Jersey框架三:Jersey对HTTPS的 ...

  5. Java中定时器的使用

    import java.text.SimpleDateFormat; import java.util.Date; import java.util.Timer; import java.util.T ...

  6. Android学习十九:ContentProvider初步

    一.Content Provider基本概念 1.ContentProvider为存储和获取数据提供了统一的接口.ContentProvide对数据进行封装.不用关心数据存储的细节.使用表的形式来组织 ...

  7. nginx学习12 ngx_cycle_t 和 ngx_init_cycle

    在nginx在启动过程,ngx_init_cycle这个函数最初始工作.变量的初始化存储在ngx_cycle_t这个结构体中,为了深入了解这个函数都做了那些初始化工作,就化时间研究了一下.并写下来以便 ...

  8. ajax基本概念,方法

    ajax    Asynchronous javascript and xml异步的 javascript and XMLajax 是一门在不刷新网页的情况下,与服务器进行交互更新部分网页的技术: 传 ...

  9. C++ 在字符串中插入子串+推断字符串是否由空格组成

    // Example3.cpp : 定义控制台应用程序的入口点. #include "StdAfx.h" #include <string> #include < ...

  10. 外网SSH访问内网LINUX的N种方法

    外网SSH访问内网LINUX的N种方法 http://www.nat123.com/Pages_8_260.jsp 一,动态公网IP环境 1,环境描述: 路由器分配的是动态公网IP,且有路由管理权限, ...