LeetCode 45 Jump Game II(按照数组进行移动)
package leetcode_50; /***
*
* @author pengfei_zheng
* 给定数组,找出最小跳动选择
*/
public class Solution45 {
public int jump(int[] nums) {
if (nums == null || nums.length < 2) {
return 0;
}
int left = 0;
int right = nums[0];
int step = 1;
while (left <= right) {
if (right >= nums.length - 1) {
return step;
}
int max = Integer.MIN_VALUE;
for (; left <= right; left++) {
max = Math.max(max, left + nums[left]);
}
if (max > right) {
left = right;
right = max;
step++;
}
}
return -1;
}
}
LeetCode 45 Jump Game II(按照数组进行移动)的更多相关文章
- Leetcode 45. Jump Game II(贪心)
45. Jump Game II 题目链接:https://leetcode.com/problems/jump-game-ii/ Description: Given an array of non ...
- [leetcode]45. Jump Game II青蛙跳(跳到终点最小步数)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- 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 跳跃游戏 II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] 45. Jump Game II 跳跃游戏之二
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] 45. Jump Game II 解题思路
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [leetcode] 45. Jump Game II(hard)
原题 题意: 是Jump Game的衍生题(题解),题意求跳到最后一格所需最少步数,(默认所测数据永远可以跳到最后一格). 思路: 利用贪心,遍历数组,记录在每一步可跳跃到的最大区域. 1.当前步数 ...
- [LeetCode] 45. Jump game II ☆☆☆☆☆(跳跃游戏 2)
https://leetcode-cn.com/problems/jump-game-ii/solution/xiang-xi-tong-su-de-si-lu-fen-xi-duo-jie-fa-b ...
- Leetcode 45. Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
随机推荐
- mysql4.5 更改密码,登录命令行闪退
登录到命令行 修改密码: 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:mysql> set passwor ...
- Material Design Support 8大控件介绍
TextInputLayout 显示提示信息 能够通过调用setError()在EditText以下显示一条错误信息 FloatingActionButton 悬浮操作按钮 Snackbar 相当于底 ...
- [转]仿91助手的PC与android手机通讯
仿91助手的PC与android手机通讯 原文 知道91助手和豌豆莢吧? 说到这两个东西,最让人好奇的应该是就是和手机的交互了.我之前有研究过电脑和安卓的交互,基本功能已经走通了,在这里我想分享一下. ...
- jQuery form的load函数与el表达式赋值的冲突问题
问题: 在使用el表达式给表单中的项赋初始值的时候,总是失败,物流公司没有自动选中,物流单号也没有显示值. <form id="form" method="post ...
- VS2008编译错误:error C2065: 'PMIB_TCPSTATS' : undeclared identifier c:\program files (x86)\microsoft sdks\windows\v7.0a\include\iphlpapi.h 411
安装了VS2008编译之前的程序,结果出现了编译错误,以为是VS2008的Sp1补丁没装好,重装补丁后还是不行,编译错误如下: 双击错误会定位在iphlpapi.h中, 一个可行的解决办法是:把iph ...
- UnitOfWork 更新实体出错解决办法
用UnitOfWork进行实体更新的时候,再查询实体一次,再去更新的时候会报如下错误: Attaching an entity of type 'TinyFrame.Data.DomainModel. ...
- Python多线程运行带多个参数的函数
在python中经常会到用多线程处理某个函数来缩短运行时间. from multiprocessing import Pool def work(x): return x+1 pool = Pool( ...
- Maven -- 发布jar包至远程仓库
啦啦啦
- Go之函数直接实现接口
//1.定义一个接口 type Run interface { Runing() } //2.定义一个函数类型 type Runer func() //3.让函数直接实现接口 func (self R ...
- Nginx(十一)-- keepalived简介
1. 什么是keepalived 基于VRRP(虚拟路由器冗余协议)来实现对web服务的高可用方案. keepalived下载地址:http://download.csdn.net/detail/u0 ...