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
相关推荐
l1t21 小时前
DeepSeek辅助编写的利用位掩码填充唯一候选数方法求解数独SQL
数据库·sql·算法·postgresql
Z1Jxxx21 小时前
反序数反序数
数据结构·c++·算法
副露のmagic21 小时前
更弱智的算法学习 day25
python·学习·算法
求梦82021 小时前
【力扣hot100题】移动零(1)
算法·leetcode·职场和发展
NAGNIP21 小时前
机器学习中的数据预处理方法大全!
算法·面试
涛涛北京1 天前
Soft-Actor-Critic算法-连续环境
算法
vyuvyucd1 天前
C++排序算法全解析
java·数据结构·算法
胡萝卜不甜1 天前
算法宗门---迪杰斯特拉Dijkstra(最短路径算法)
算法
练习时长一年1 天前
LeetCode热题100(爬楼梯)
算法·leetcode·职场和发展
朔北之忘 Clancy1 天前
2020 年 6 月青少年软编等考 C 语言一级真题解析
c语言·开发语言·c++·学习·算法·青少年编程·题解