当前位置:网站首页>Jump game of leetcode topic analysis
Jump game of leetcode topic analysis
2022-06-23 09:36:00 【ruochen】
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
For example:
A = [2,3,1,1,4], return true.
A = [3,2,1,0,4], return false.
Set variables maxStep Is the maximum number of steps that you can jump , Over array length , It means you can jump out ; Otherwise, you can't jump out .
that maxStep How to find out ?numsi + i On behalf of : Jump from current position , The farthest position you can jump .
public boolean canJump(int[] nums) {
if (nums == null || nums.length == 0) {
return false;
}
int maxStep = 0;
for (int i = 0; i < nums.length; i++) {
if (maxStep >= nums.length - 1) {
return true;
}
if (nums[i] == 0 && maxStep == i) {
return false;
}
maxStep = Math.max(maxStep, nums[i] + i);
}
return true;
}边栏推荐
猜你喜欢
随机推荐
Redis learning notes - data type: Set
[GXYCTF2019]BabyUpload
Redis学习笔记—遍历键
[ciscn2019 North China Day2 web1]hack world
Redis学习笔记—慢查询分析
Sequential representation and implementation of sequencelist -- linear structure
栈(Stack)的链式实现详解----线性结构
[SUCTF 2019]CheckIn
分布式常见面试题
【CTF】bjdctf_ 2020_ babyrop
ICLR 2022 | 视频中的动态卷积TAdaConv以及高效的卷积视频理解模型TAdaConvNeXt
Difference between global shutter and roller shutter
Servlet-02 生命周期
Implementation of s5p4418 bare metal programming (replace 2ndboot)
Redis学习笔记—redis-benchmark详解
RGB and CMYK color modes
Redis learning notes - redis cli explanation
ionic5表单输入框和单选按钮
Learn SCI thesis drawing skills (E)
Redis learning notes - geographic information location (GEO)

![[GXYCTF2019]BabyUpload](/img/82/7941edd523d86f7634f5532ab97717.png)






