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
相关推荐
炽烈小老头19 小时前
【 每天学习一点算法 2026/04/21】螺旋矩阵
学习·算法
未来转换20 小时前
基于A2A协议的生产应用实践指南(Java)
java·开发语言·算法·agent
谭欣辰20 小时前
AC自动机:多模式匹配的高效利器
数据结构·c++·算法
joker_sxj20 小时前
论文阅读-DeepSeek-mHC
论文阅读·算法
sheeta199820 小时前
LeetCode 每日一题笔记 日期:2026.04.21 题目:1722. 执行交换操作后的最小汉明距离
笔记·算法·leetcode
鲸渔20 小时前
【C++ 跳转语句】break、continue、goto 与 return
开发语言·c++·算法
AI科技星20 小时前
基于螺旋元逻辑的宇宙统一场论底层公理构建(乖乖数学)
算法·机器学习·数学建模·数据挖掘·量子计算
qiqsevenqiqiqiqi21 小时前
MC0550鱼肠剑试锋芒
数据结构·算法
仍然.21 小时前
算法题目---链表
数据结构·算法·链表
luoganttcc21 小时前
华为昇腾(Ascend)等芯片,同样存在“寄存器 / 片上存储资源限制并发”的问题
算法·华为