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
相关推荐
客卿123几秒前
力扣--数组 入门三题-485/283/27---刷题笔记+思路分析+C语言
c语言·笔记·leetcode
Physicist in Geophy.2 分钟前
矩阵的本质
算法·机器学习·矩阵
小龙报2 分钟前
【算法通关指南:算法基础篇 】贪心专题之简单贪心:1.最大子段和 2.纪念品分组
c语言·数据结构·c++·算法·ios·贪心算法·动态规划
AlenTech3 分钟前
148. 排序链表 - 力扣(LeetCode)
数据结构·leetcode·链表
君义_noip8 小时前
信息学奥赛一本通 1661:有趣的数列 | 洛谷 P3200 [HNOI2009] 有趣的数列
c++·算法·组合数学·信息学奥赛·csp-s
程序员:钧念8 小时前
深度学习与强化学习的区别
人工智能·python·深度学习·算法·transformer·rag
leaves falling9 小时前
c语言-扫雷游戏
c语言·单片机·游戏
英英_9 小时前
MATLAB数值计算基础教程
数据结构·算法·matlab
一起养小猫10 小时前
LeetCode100天Day14-轮转数组与买卖股票最佳时机
算法·leetcode·职场和发展
hele_two10 小时前
快速幂算法
c++·python·算法