【LeetCode】45. Jump Game II
Jump Game II
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.)
ret:目前为止的jump数
curRch:从A[0]进行ret次jump之后达到的最大范围
curMax:从0~i这i+1个A元素中能达到的最大范围
当curRch < i,说明ret次jump已经不足以覆盖当前第i个元素,因此需要增加一次jump,使之达到
记录的curMax。
class Solution {
public:
int jump(int A[], int n) {
int ret = ;
int curMax = ;
int curRch = ;
for(int i = ; i < n; i ++)
{
if(curRch < i)
{
ret ++;
curRch = curMax;
}
curMax = max(curMax, A[i]+i);
}
return ret;
}
};

【LeetCode】45. Jump Game II的更多相关文章
- 【LeetCode】45. Jump Game II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...
- 【一天一道LeetCode】#45. Jump Game II
一天一道LeetCode系列 (一)题目 Given an array of non-negative integers, you are initially positioned at the fi ...
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- 【LeetCode】731. My Calendar II 解题报告(Python)
[LeetCode]731. My Calendar II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...
- 【LeetCode】137. Single Number II 解题报告(Python)
[LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...
- 【LeetCode】227. Basic Calculator II 解题报告(Python)
[LeetCode]227. Basic Calculator II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...
- 【LeetCode】113. Path Sum II 解题报告(Python)
[LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...
- [Leetcode][Python]45: Jump Game II
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 45: Jump Game IIhttps://oj.leetcode.com ...
- 【Leetcode】Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...
随机推荐
- 0, \0, NULL
字符串.字符数组输入.输出与'\0'的问题 原创首发,欢迎转载! 作者按 字符串.字符数组以"%s"格式输入时,以遇到'空格'为这个字符串输入结束. 字符串.字符数组以" ...
- 中国计算机学会CCF推荐国际学术会议和期刊目录(PDF版,2015年)
total: CCF推荐国际学术会议和期刊目录(下载) parts: 点击下载: 计算机体系结构并行与分布计算存储系统.pdf 点击下载: 计算机网络.pdf 点击下载: 网络与信息安全.pdf ...
- Ubuntu双系统安装
原文链接: http://www.jianshu.com/p/2eebd6ad284d 作者 Volcanoo 2016.01.31 00:07 字数 1737 阅读 141859评论 161喜欢 ...
- 聊聊clean code
clean code,顾名思义就是整洁的代码,或者说清晰.漂亮的代码,相信大多数工程师都希望自己能写出这样的代码. 也许这是个千人千面的话题,每个工程师都有自己的理解.比如我,从一个天天被骂代码写得烂 ...
- Informatica 常用组件Expression之二 创建EXP组件
在 Mapping Designer 中选择"转换-创建".选择表达式转换.为它输入一个名称(惯例为 EXP_TransformationName)并单击"确定" ...
- 牛气冲天的Iframe应用笔记
纵观时下网站,本来网速就有些慢,可是几乎每页都要放什么Banner,栏目图片,版权等一大堆雷同的东西,当然,出于网站风格统一.广告效应的需要,本无可厚非,可毕竟让用户的钱包为这些“点缀“的东西”日益消 ...
- 搜狐视频Redis私有云平台CacheCloud
一.CacheCloud是做什么的 CacheCloud提供一个Redis云管理平台:实现多种类型(Redis Standalone.Redis Sentinel.Redis Cluster)自动部署 ...
- RS交叉表自动汇总后百分比列显示错误之解决方案
可以说在从事Cognos开发的过程中,仅仅对数据展现而言,大多数用户使用最多的工具便是Report Studio了,此工具可以帮助我们快速的构建一些可供用户自主选择的数据报告.当然我个人认为没有什么开 ...
- 老三星手机i9001刷机记录
家里的老的三星i9001,准备给我妈用,打算刷机,但又实在头疼那些复杂的刷机技术,昨天研究了一下,用比较简单的方法完成刷机,记录如下: 用卡刷比较简单,线刷不考虑 进入恢复模式的方法:1.电源+音量加 ...
- 理解进程调度时机跟踪分析进程调度与进程切换的过程(Linux)
----------------------------------------------------------------------------------- 理解进程调度时机跟踪分析进程调度 ...