当前位置:网站首页>Leetcode45. 跳跃游戏 II
Leetcode45. 跳跃游戏 II
2022-07-16 13:44:00 【Java全栈研发大联盟】
题目传送地址: https://leetcode.cn/problems/jump-game-ii/

代码如下:
public static int jump(int[] nums) {
int result = 0; //走的总步数
for (int i = 0; i < nums.length - 1; i++) {
int j = i + 1;
int max = 0;
result++;
int nextIndex = 0; //下一个能跑最远的有潜力的点
if (i + nums[i] >= nums.length - 1) {
return result;
}
//找出下一个能跑最远的点。
while (j <= i + nums[i]) {
if (nums[j] + j > max) {
max = nums[j] + j;
nextIndex = j;
}
j++;
}
i = nextIndex-1;
}
return result;
}
边栏推荐
- MFC problem solving process appmanage
- 【golang】cannot unmarshal xxx “ into Go struct field xxx of type xxx
- 【第33天】或运算 | 的使用 | 连续低位0变1
- 输入一个url全过程详解
- ROS 创建工作空间流程
- C#网络应用编程,实验一:WPF练习
- Tips for copying content in web pages without login account
- IDEA安装、配置、测试
- (pytorch进阶之路三)conv2d
- Concept correlation and pattern matching of strings
猜你喜欢

PICASSO,一个高效的搜推广稀疏训练解决方案

开箱:阿里技术人在读什么书?

Error ora-01017 is reported after RMAN recovers

【产品人卫朋】2022年产品人必备的13个设计类网站(1.0版)

Introduction to replacement technology of SAP ABAP CDs view view
![[I2C of Renesas ra6m4 development board reads bmp180 air pressure and temperature]](/img/88/0777b7f241df2e0169a724343ba482.png)
[I2C of Renesas ra6m4 development board reads bmp180 air pressure and temperature]

Resolved SQL_ ERROR_ INFO: “You have an error in your SQL syntax; check the manual that corresponds to your

Xray安装使用

【golang】cannot unmarshal xxx “ into Go struct field xxx of type xxx

20220715 国内Conda不fq安装Pytorch最新版本的方法
随机推荐
An interesting keyboard bug debugging experience (I want to break my colleagues' legs)
module ‘sklearn.datasets‘ has no attribute ‘fetch_mldata‘
The web crawler crawls the titles and contents of all chapters of the romance of the Three Kingdoms (beautifulsoup analysis)
Lime of Py: a detailed introduction to the introduction, installation and use of the lime Library
(pytorch进阶之路三)conv2d
The simple solution the boss wants vs. the needs the programmer understands | cartoon
HALCON联合C#检测表面缺陷——ROI交互(三)(和图片同步缩放裁剪等功能)
(pytorch进阶之路四)Vision Transformer
一次有趣(想打断同事腿)的键盘BUG调试经历
【C#】正序、逆序、最大值、最小值和平均值
Touche pussy cat
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
20220715 国内Conda不fq安装Pytorch最新版本的方法
(Fibonacci sequence) use the function to output the number of Fibonacc within the specified range (PTA)
达梦数据库表SQL语句
C#网络应用编程,实验5:数据流练习
C#网络应用编程,实验4:线程管理练习
C#求完全数,输出水仙花以及类的使用
请查收,您有一份阿里先锋开源项目清单
sqlmap语法介绍