} 用错误的数组run code一下,看上去答案应该是正确的,不过是414ms超时,由此发现之前的算法果然太暴力。 于是,类似于递归,从前到后遍历,遇到的第一个i+nums[i]将作为新的所求目标位置,并且将result+1,直到所求位置pos到达0或者1为止。结果1ms,但是仍然超时。这到底是什么我也并不知道。。。 代码如下: 1 2 ...
代码 public class Solution { public boolean canJump(int[] nums) { int max = 0, i = 0; for(i = 0; i <= max && i < nums.length; i++){ max = Math.max(max, nums[i] + i); } return i == nums.length; } } Jump Game II Given an array of non-negative integers, you ar...
1.一维DP,jump[i]表示到达位置i剩余的最大步数 1publicbooleancanJump(int[] A) {2//Start typing your Java solution below3//DO NOT write main() function4intlen =A.length;5//using DP6int[] jump =newint[len];7jump[0] = 0;89for(inti = 1; i < len; i++){10jump[i] = Math.ma...
LeetCode 1340. Jump Game V (Java版; Hard) 题目描述 Given an array of integers arr and an integer d. In one step you can jump from index i to index: i + x where: i + x < arr.length and 0 < x <= d. i - x where: i - x >= 0 and 0 < x <= d. In addition, you ...
【LeetCode】45. Jump Game II 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. Your goal is to reach the last index in the minimum number of jumps. ...
https://leetcode.cn/problems/jump-game-ii/solution/tiao-yue-you-xi-ii-by-leetcode-solution/ 第一题是力扣原题,有O(n)的贪心方法,不用在内循环里找最大值。 查看原帖 5 04-03 18:09 门头沟学院 前端工程师 新东方内推 新东方内推码 🌈“不设边界,无限可能”——新东方(南昌)2025届春招进行中!
leetcode / solution / 0000-0099 / 0045.Jump Game II / README_EN.md README_EN.md 2.78 KB 一键复制 编辑 原始数据 按行查看 历史 ylb 提交于 4年前 . feat: add solutions to lc problem: No.0045. Jump Game II 45. Jump Game II Description Solutions Python3 Java ...
leetcode / solution / 0000-0099 / 0055.Jump Game / README_EN.md README_EN.md 2.58 KB 一键复制 编辑 原始数据 按行查看 历史 ylb 提交于 4年前 . feat: add solutions to lc problem: No.0055. Jump Game 55. Jump Game Description Solutions Python3 Java C++ Go C# 55....
55. 跳跃游戏 - 给你一个非负整数数组 nums ,你最初位于数组的 第一个下标 。数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个下标,如果可以,返回 true ;否则,返回 false 。 示例 1: 输入:nums = [2,3,1,1,4] 输出:true 解释
😏 LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解 - leetcode/solution/1300-1399/1306.Jump Game III/README.md at main · lei1024/leetcode