当前位置:网站首页>Leetcode55. Jumping game
Leetcode55. Jumping game
2022-07-25 04:48:00 【Java full stack R & D Alliance】
Title transmission address : https://leetcode.cn/problems/jump-game/

The code is as follows :
public static boolean canJump(int[] nums) {
// Dealing with boundary conditions
if (nums.length == 1) {
return true;
}
for (int i = 0; i < nums.length - 1; i++) {
int j = i + 1;
int nextStep = i; // Where to jump next
int farthest = 0; // Farthest
while (j < nums.length && j <= i + nums[i]) {
if (j + nums[j] > farthest) {
farthest = j + nums[j];
nextStep = j;
}
j++;
}
if (farthest >= nums.length - 1) {
return true;
}
if (nums[nextStep] == 0 && nextStep < nums.length - 1) {
return false;
}
i = nextStep - 1;
}
return false;
}
边栏推荐
- Idea2021 installation
- 今天很重要
- Druid connection pool - strong self-study from 0. Those who don't understand Druid can click in. If you know not to click in, you will think I'm wordy
- 看问题的角度
- Thinking from the perspective of Aya
- Source code | opencv DNN + yolov7 target detection
- Introduction to fundamentals of operations research [1]
- Chart is code: build a new generation of graphics library in a coded way -- feekin
- Introduction to computing system hardware (common servers)
- PyG搭建GCN实现链接预测
猜你喜欢

Druid连接池——从0开始坚强的一点点的自学,Druid一点不懂的可以点进来,懂得别点进来,点进来你会嫌我啰嗦的

Kubesphere 3.3.0 offline installation tutorial

Interviewer: explain the core principle of ThreadLocal

Grafana visual configuration diagram histogram
![[CTF learning] steganography set in CTF -- picture steganography](/img/32/2da78bd5866cfab9ee64dfcb1c1204.png)
[CTF learning] steganography set in CTF -- picture steganography

2019 telecast retest test questions

GDT,LDT,GDTR,LDTR

Gradle test and idea test

Summary of UPR optimization suggestions of unity

运筹学基础【一】 之 导论
随机推荐
Data Lake (16): structured streaming writes iceberg in real time
01 create project warehouse
How many rows does PostgreSQL need to partition for each table?
Chart is code: build a new generation of graphics library in a coded way -- feekin
Sony announced the closure of Beijing mobile phone factory! The production line will be moved to Thailand, and the cost can be reduced by half!
How can test / development programmers with 5 years of experience break through the technical bottleneck? Common problems in big factories
LVGL 8.2 Tabview & Window
市场是对的
mitt.js:小型事件发布订阅库
LVGL 8.2 Span
Paper:《Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Condi
数据湖(十六):Structured Streaming实时写入Iceberg
[golang from introduction to practice] poker licensing game
[ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术
In the Internet of things market, Bosch sensor has launched a number of new solutions
看问题的角度
阿亚的角度思考
Apple airpower was forced to cancel its launch two years after it was launched! Uncover the reason!
QT download installation tutorial
Pychart configuration pyqt5