Python | Leetcode Python题解之第45题跳跃游戏II

题目:

题解:

python 复制代码
class Solution:
    def jump(self, nums: List[int]) -> int:
        n = len(nums)
        maxPos, end, step = 0, 0, 0
        for i in range(n - 1):
            if maxPos >= i:
                maxPos = max(maxPos, i + nums[i])
                if i == end:
                    end = maxPos
                    step += 1
        return step
相关推荐
ZZHow10242 小时前
02OpenCV基本操作
python·opencv·计算机视觉
计算机学长felix2 小时前
基于Django的“酒店推荐系统”设计与开发(源码+数据库+文档+PPT)
数据库·python·mysql·django·vue
站大爷IP2 小时前
Python随机数函数全解析:5个核心工具的实战指南
python
悟乙己2 小时前
使用 Python 中的强化学习最大化简单 RAG 性能
开发语言·python·agent·rag·n8n
max5006002 小时前
图像处理:实现多图点重叠效果
开发语言·图像处理·人工智能·python·深度学习·音视频
AI原吾2 小时前
玩转物联网只需十行代码,可它为何悄悄停止维护
python·物联网·hbmqtt
云动雨颤2 小时前
Python单元测试入门:3个核心断言方法,帮你快速定位代码bug
python·单元测试
SunnyDays10113 小时前
Python 实现 HTML 转 Word 和 PDF
python·html转word·html转pdf·html转docx·html转doc
共享家95273 小时前
优先搜索(DFS)实战
算法·leetcode·深度优先
跟橙姐学代码3 小时前
Python异常处理:告别程序崩溃,让代码更优雅!
前端·python·ipython