当前位置:网站首页>【刷题篇】跳跃游戏
【刷题篇】跳跃游戏
2022-06-09 21:55:00 【m0_60631323】
一、题目
给你一个非负整数数组 nums ,你最初位于数组的第一个位置。
数组中的每个元素代表你在该位置可以跳跃的最大长度。
你的目标是使用最少的跳跃次数到达数组的最后一个位置。
假设你总是可以到达数组的最后一个位置
二、题解
2.1思路

2.2 源码
public int jump(int[] nums) {
if(nums==null||nums.length==0){
return 0;
}
int step=0;
int cur=0;
int next=0;
for (int i = 0; i < nums.length; i++) {
if(cur<i){
step++;
cur=next;
}
next=Math.max(next,i+nums[i]);
}
return step;
}
边栏推荐
- Pi of C language test question 162
- 基础查询语句
- 2022 safety production month activity starts safety production and epidemic prevention and control
- 2022安全生產月活動啟動安全生產與疫情防控兩手抓
- 第四范式陈雨强:企业智能决策的下一代技术「强化学习 + 环境学习」
- Cookie 和 Session 工作流程
- Industrial Internet + Digital Integrated Management cloud platform for hazardous chemical safety production
- The fourth paradigm chenyuqiang: the next generation technology of enterprise intelligent decision-making "reinforcement learning + environmental learning"
- FPN-Feature Pyramid Network
- GameFi新的启程,AQUANEE将于6.9日登陆Gate以及BitMart
猜你喜欢

Web3中的 重复的 Web1历程

第四范式陈雨强:企业智能决策的下一代技术「强化学习 + 环境学习」

继承的所有特征

【滤波器】基于时变维纳滤波器实现语音去噪含Matlab源码

稍微复杂的查询

The fourth paradigm chenyuqiang: the next generation technology of enterprise intelligent decision-making "reinforcement learning + environmental learning"

2022 safety production month activity starts safety production and epidemic prevention and control

2022安全生產月活動啟動安全生產與疫情防控兩手抓

2022年最系统的自动化测试,测试开发面试题,10k以下不建议看

86.(leaflet之家)leaflet军事标绘-直线箭头采集
随机推荐
2022安全生產月活動啟動安全生產與疫情防控兩手抓
中金证券开户怎么样?安全吗?开户
函数对象(仿函数)
为什么健身?
从小开始勤奋
Clickhouse series: Clickhouse optimized block+lsm
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
Intelligent prevention and control of safety production risk at construction site in flood season
Some Oracle DDL operations
Slightly more complex queries
调查显示macOS应用开发者普遍表示产品如何被用户发现是他们最大的挑战
[translation paper] a progressive morphological filter for removing nonground measurements from airport lidar dat
The 14th Sudoku - true Sudoku - day 5-20220120
IAR打开工程编译未响应、卡死 & STM32CubeMX生成工程时出错
实验一:在FW上配置静态路由实现互通
2022安全生产月活动启动安全生产与疫情防控两手抓
TL, how do you manage project risks?
The Little Schemer 中文版
Bluetooth protocol analysis (7)_ Technical analysis of ble connection
【图像重建】基于正则化的图像超分辨重建附matlab代码