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
相关推荐
猿人谷20 分钟前
Pareto:为什么真正的优化,不是寻找一个最优解?
后端·算法·aigc
cooldream200930 分钟前
计算机专业本科毕业设计系列07——类型④:算法与理论研究
算法·毕业设计·计算机专业·课程设计
劲夫学编程1 小时前
leetcode: 字母异位词分组
算法·leetcode
wy_hhxx1 小时前
[Leetcode] 动态规划(打家劫舍、0-1背包、完全背包)
算法·leetcode·动态规划·完全背包·0-1背包
禁默2 小时前
AI搓童年游戏-用华为云码道 CodeArts(Kimi-K3.1-Pro)从零写一个零依赖俄罗斯方块
人工智能·游戏·华为云
m0_547486662 小时前
《智能计算》全套课件PDF(武汉工程大学)
算法·贝叶斯算法·智能计算
Shaoshing2 小时前
LeetCode100 32.最长有效括号
java·数据结构·leetcode
weixin_307779132 小时前
Jupyter SQL 表血缘分析并导出 Excel
开发语言·python·sql·算法·excel
Lazyafei3 小时前
560. 和为 K 的子数组
数据结构·算法
2601_949695593 小时前
显卡驱动版本过低玩不了游戏怎么办?如何检查最新驱动?
游戏·电脑·显卡·显卡驱动·驱动程序