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
相关推荐
小白程序员成长日记16 分钟前
2025.11.21 力扣每日一题
算法·leetcode·职场和发展
小年糕是糕手1 小时前
【C++】C++入门 -- inline、nullptr
linux·开发语言·jvm·数据结构·c++·算法·排序算法
高洁011 小时前
具身智能-普通LLM智能体与具身智能:从语言理解到自主行动
人工智能·深度学习·算法·aigc·知识图谱
LBuffer1 小时前
DOS游戏水浒传
游戏·修改·解包
星期天21 小时前
3.2联合体和枚举enum,还有动态内存malloc,free,calloc,realloc
c语言·开发语言·算法·联合体·动态内存·初学者入门·枚举enum
Andy2 小时前
回文子串数目--动态规划算法
算法·动态规划
sin_hielo2 小时前
leetcode 1930
算法·leetcode
塞北山巅2 小时前
相机自动曝光(AE)核心算法——从参数调节到亮度标定
数码相机·算法
聆风吟º2 小时前
【数据结构入门手札】算法核心概念与复杂度入门
数据结构·算法·复杂度·算法的特性·算法设计要求·事后统计方法·事前分析估算方法
vir023 小时前
密码脱落(最长回文子序列)
数据结构·c++·算法