LeetCode(力扣)45. 跳跃游戏 IIPython

LeetCode45. 跳跃游戏 II

题目链接

https://leetcode.cn/problems/jump-game-ii/description/

代码

python 复制代码
class Solution:
    def jump(self, nums: List[int]) -> int:
        if len(nums) == 1:
            return 0
        curdis = 0
        nextdis = 0
        step = 0
        for i in range(len(nums)):
            nextdis = max(nums[i] + i, nextdis)
            if i == curdis:
                step += 1
                curdis = nextdis
                if nextdis >= len(nums) - 1:
                    break
        return step
相关推荐
Fly Wine1 小时前
Leetcode之有效字母异位词
算法·leetcode·职场和发展
程序员夏末3 小时前
【LeetCode | 第七篇】算法笔记
笔记·算法·leetcode
csdn_aspnet3 小时前
C/C++ 两个凸多边形之间的切线(Tangents between two Convex Polygons)
c语言·c++·算法
数据皮皮侠4 小时前
中国城市间地理距离矩阵(2024)
大数据·数据库·人工智能·算法·制造
3GPP仿真实验室4 小时前
深度解析基站接收机核心算法:从 MRC 到 IRC 的空间滤波演进
算法
Boop_wu4 小时前
[Java 算法] 动态规划(1)
算法·动态规划
WolfGang0073214 小时前
代码随想录算法训练营 Day18 | 二叉树 part08
算法
张老师带你学4 小时前
UnityVR弯曲UI
科技·游戏·unity·游戏引擎·模型
hanlin035 小时前
刷题笔记:力扣第43、67题(字符串计算)
笔记·算法·leetcode
yang_B6215 小时前
最小二乘法 拟合平面
算法·平面·最小二乘法