当前位置:网站首页>Leetcode 45 jump game II
Leetcode 45 jump game II
2022-06-12 01:47:00 【baj001】
Ideas
- Different from ordinary Jumping Games , This question limits the minimum number of jump steps
- Defines the of this jump end Location , It is also the position for the next jump
- stay for In circulation ,i To meet the i < length - 1 instead of i < length; Because if i < length It's possible i Is the last position of the array , At this time, the last position of the array is counted , So the function will be out of bounds .
- stay for The maximum takeoff position is continuously updated in the cycle , When i == end When , take end to update It is the farthest position you can jump to currently , then steps++
class Solution {
public int jump(int[] nums) {
int length = nums.length;
int end = 0;// The right boundary of the reachable range of the last jump ( The next rightmost takeoff point )
int maxPosition = 0; // The farthest position you can jump to now
int steps = 0; // The number of jumps
// As follows i < length - 1 Is a key location , Can't make i < length
for (int i = 0; i < length - 1; i++) {
maxPosition = Math.max(maxPosition, i + nums[i]);
// We have reached the right boundary of the last jump
if (i == end) {
// The farthest position you can jump to now becomes the right boundary of the next take-off position
end = maxPosition;
// Go to the next jump
steps++;
}
}
return steps;
}
}
边栏推荐
- Design practice of rongyun Im on electron platform
- Three main factors determining advertising quality
- 竞价广告每次点击出价多少钱是固定的吗?
- php安全开发 12博客系统的 系统模块信息的修改
- MySQL表常用操作思维导图
- Wechat applet - a case of comparing the size of numbers
- MySQL实训报告【带源码】
- PCA from 0 to 1
- Wide match modifier symbol has been deprecated, do not use
- 如何为Excel中的单元格自动填充颜色
猜你喜欢

2022 blind box applet app has become a new drainage outlet for enterprises

Point cloud perception algorithm interview knowledge points (I)

Huawei, this is too strong

博文推荐|BookKeeper - Apache Pulsar 高可用 / 强一致 / 低延迟的存储实现

Entity class dto to VO is converted through plug-in

Blog recommended | bookkeeper - Apache pulsar high availability / strong consistency / low latency storage implementation

Bracket generation (backtracking)

php开发 博客系统的公告模块的建立和引入

Tiobe - programming language ranking in June 2022

Linux(CentOS6)安装MySQL5.5版本数据库
随机推荐
Redis實現消息隊列的4種方案
Perceptron from 0 to 1
[learn FPGA programming from scratch -20]: quick start chapter - operation steps 4-2-quick use of Altera quartz II tool (Modelsim co simulation, program download to altera development board)
Ce soir - là, j'ai battu mon collègue...
MySQL高级部分知识点
MySQL表常用操作思维导图
PCA from 0 to 1
【科普视频】到底什么是透镜天线?
Point cloud perception algorithm interview knowledge points (I)
LeetCode Algorithm 997. 找到小镇的法官
Operating mechanism of Google ads bidding
Simulated 100 questions and simulated examination for safety management personnel of metal and nonmetal mines (small open pit quarries) in 2022
Wechat applet - a case of comparing the size of numbers
Fatal error in launcher: unable to create process using
kmeans从0到1
国资入股,建业地产这回稳了吗?
Linux(CentOS7)安裝MySQL-5.7版本
Quatre schémas de mise en file d'attente des messages pour redis
“還是學一門技術更保險!”杭州校區小哥哥轉行軟件測試,喜提10K+雙休!
How to buy children's serious illness insurance, what to pay attention to and how to choose products