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
相关推荐
随意起个昵称3 小时前
线性dp-计数类题目10(ZBRKA)
算法·动态规划
wgc2k3 小时前
Node.js游戏服务器项目移植 3-手撸简单的内存泄露监控
服务器·游戏·node.js
Navigator_Z9 小时前
LeetCode //C - 1089. Duplicate Zeros
c语言·算法·leetcode
云泽80812 小时前
C++ 可调用对象通关指南:深度解析 Lambda 表达式、function 包装器与 bind 绑定器
开发语言·c++·算法
wlsh1512 小时前
Go 迭代器
算法
winlife_12 小时前
在 Unity 里用 AI 做游戏:funplay-unity-mcp 从安装到第一次让 AI 改场景
人工智能·游戏·unity·ai编程·claude·mcp
语戚12 小时前
力扣 3161. 块放置查询:线段树解法(Java 实现)
java·算法·leetcode·面试·线段树·力扣·
CS创新实验室13 小时前
从顺序表到动态数组:数据结构的永恒基石与现代语言的优雅封装
数据结构·算法
Black蜡笔小新14 小时前
自动化AI算法训练服务器DLTM训推一体化平台助力农业生产管理实现安全智能化
人工智能·算法·自动化
8Qi815 小时前
LeetCode 23. 合并 K 个升序链表 —— 小顶堆(PriorityQueue)
数据结构·算法·leetcode·链表·