Jump Game II
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的更多相关文章
- 57. Jump Game && Jump Game II
Jump Game Given an array of non-negative integers, you are initially positioned at the first index o ...
- [Leetcode][Python]45: Jump Game II
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 45: Jump Game IIhttps://oj.leetcode.com ...
- 55 Jump Game i && 45 Jump Game ii
Jump Game Problem statement: Given an array of non-negative integers, you are initially positioned a ...
- LeetCode: Jump Game II 解题报告
Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...
- 【LeetCode】45. Jump Game II
Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...
- leetCode 45.Jump Game II (跳跃游戏) 解题思路和方法
Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...
- 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 ...
- Leetcode 45. Jump Game II(贪心)
45. Jump Game II 题目链接:https://leetcode.com/problems/jump-game-ii/ Description: Given an array of non ...
- [leetcode解题记录]Jump Game和Jump Game II
Jump Game Given an array of non-negative integers, you are initially positioned at the first index o ...
- leetcode 55. Jump Game、45. Jump Game II(贪心)
55. Jump Game 第一种方法: 只要找到一个方式可以到达,那当前位置就是可以到达的,所以可以break class Solution { public: bool canJump(vecto ...
随机推荐
- [Ogre][地形]OgreTerrain的实现原理分析
转自:http://www.xuebuyuan.com/1482609.html 一.世界地图 将整个世界切分成多个Tile,每个Tile大小相同,用二维坐标形式索引起来,如图: 中心点(0,0)位置 ...
- Linux hrtimer分析(2)
http://blog.csdn.net/angle_birds/article/details/17375901 本文介绍Linux2.6.29中,配置高精度模式的hrtimer与未配置高精度模式时 ...
- Find them, Catch them
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36488 Accepted: 111 ...
- Oracle数据库的启动与停止
oracle linux下开启与关闭 .启动ORACLE监听 首先要登录用户oracle:su - oracle oracle@localhost bin]$ lsnrctl --启动oracle监听 ...
- thinkphp隐藏中url的index.php
在本地进行测试 1.修改apache配置文件将如下代码#去掉 #LoadModule rewrite_module modules/mod_rewrite.so 在index.php 目录下新建文 ...
- 2016 ACM/ICPC Asia Regional Qingdao Online HDU5883
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 解法:先判断是不是欧拉路,然后枚举 #pragma comment(linker, "/S ...
- Android权限安全(1)自定义,检查,使用权限
1.自定义权限: <!-- 定义自定义权限 --> <permission android:name="com.example.f6k5i8.checkpermission ...
- Linux中安装Cisco Packet Tracer
Cisco Packet tracer是什么? Cisco Packet Tracer是一个强大的网络模拟工具,用于进行Cisco认证时的培训.它为我们 提供了各个路由器和网络设备的良好的接口视图,这 ...
- 动态加载JS
<script> Date.prototype.format = function(format) { var o = { , //month "d+" : this. ...
- 【转载】图解:二叉搜索树算法(BST)
原文:图解:二叉搜索树算法(BST) 摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢!“岁月极美,在于它必然的流逝”“春花 秋月 夏日 冬雪”— ...