Description:

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.

Your goal is to reach the last index in the minimum number of jumps.

For example:
Given array A = [2,3,1,1,4]

The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.)

Code:

 int jump(vector<int>& nums) {
if (nums.size() <= )
return ; int jumpNum = , curDis = , maxDis = ;
for (int i = ; i < nums.size(); ++i)
{
if (curDis < i)
{
jumpNum++;
curDis = maxDis;
}
maxDis = max(maxDis, nums[i]+i);
}
return jumpNum;
}

Jump Game II的更多相关文章

  1. 57. Jump Game && Jump Game II

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

  2. [Leetcode][Python]45: Jump Game II

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 45: Jump Game IIhttps://oj.leetcode.com ...

  3. 55 Jump Game i && 45 Jump Game ii

    Jump Game Problem statement: Given an array of non-negative integers, you are initially positioned a ...

  4. LeetCode: Jump Game II 解题报告

    Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...

  5. 【LeetCode】45. Jump Game II

    Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...

  6. leetCode 45.Jump Game II (跳跃游戏) 解题思路和方法

    Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...

  7. Leetcode 55. Jump Game & 45. Jump Game II

    55. Jump Game Description Given an array of non-negative integers, you are initially positioned at t ...

  8. Leetcode 45. Jump Game II(贪心)

    45. Jump Game II 题目链接:https://leetcode.com/problems/jump-game-ii/ Description: Given an array of non ...

  9. [leetcode解题记录]Jump Game和Jump Game II

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

  10. leetcode 55. Jump Game、45. Jump Game II(贪心)

    55. Jump Game 第一种方法: 只要找到一个方式可以到达,那当前位置就是可以到达的,所以可以break class Solution { public: bool canJump(vecto ...

随机推荐

  1. 杭电1003-Max Sum

    Max Sum Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the ...

  2. 通过URl将服务器的图片下载到本地并压缩

    private void downloadServerPic(final String url1) { new Thread() { @Override public void run() { // ...

  3. JS获取非行间样式

    我们都知道用offset函数获取元素样式是一件很方便的事,但是offset只能获取行间样式,而无法获得非行间样式,这是它的瓶颈所在. 我们都知道js获取行间样式的方法,那么js是如何获取行距样式的呢? ...

  4. The trouble of Xiaoqian

    The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  5. 华东交通大学2016年ACM“双基”程序设计竞赛 1009

    Problem Description 华盛顿在寝室洗衣服,遭到了xyf的嫌弃,于是xyf出了道题给华盛顿来做(然而并没有什么关系-v-!)xyf扔给华盛顿n个字符串,这些字符串的长度不超过10000 ...

  6. Mysql-学习笔记(==》连接查询_高级查询五)

    CREATE TABLE t( tid INT UNSIGNED NOT NULL AUTO_INCREMENT, tname VARCHAR(30), PRIMARY KEY (tid))ENGIN ...

  7. 为什么需要main函数,及其参数的用法

    首先,需要明确main函数是什么? 答:main函数是C语言约定的入口函数 C99标准里面是这样描述的: Program startup The function called at program ...

  8. centos系统下设置固定IP+dns

    笔者用的linux系统是centos版本的,在次之前linux是空白,今天我在物理机用XSHELL连接虚拟机中的centos时候出现连接失败的情况,我的第一反应就是IP是不是变了?打开虚拟机之后在终端 ...

  9. 怎样为DataTable设置主键及找行数据

    只要是数据集中都应该存在主键,以确定数据集中唯一的值.那么,我们要如何为DataTable设置主键及利用主键在DataTable索引值呢? 步骤/方法     为DataTable设置主键 DataT ...

  10. 利用jdbc处理oracle大数据---大文件和二进制文件

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...