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
相关推荐
Kt&Rs1 天前
11.9 LeetCode 题目汇总与解题思路
算法·leetcode
ゞ 正在缓冲99%…1 天前
leetcode1547.切棍子的最小成本
数据结构·算法·leetcode·动态规划
2401_841495641 天前
【LeetCode刷题】移动零
数据结构·python·算法·leetcode·数组·双指针法·移动零
开心星人1 天前
Leetcode hot100 Java刷题(二)
java·算法·leetcode
hn小菜鸡1 天前
LeetCode 153.寻找旋转排序数组中的最小值
数据结构·算法·leetcode
DeniuHe1 天前
逻辑回归(Logistic Regression)详细解释与公式推导
算法·机器学习·逻辑回归
迅量科技资讯分享1 天前
手机拍照明晰度评估:传感器尺寸像素数量与处理器算法解析
算法·三星·像素
liu****1 天前
12.线程同步与互斥
linux·数据结构·c++·算法·1024程序员节
麦烤楽鸡翅1 天前
小红书推荐系统(牛客)
java·python·算法·秋招·春招·牛客·面试算法题
王哈哈^_^1 天前
CV三大核心任务:目标检测、图像分割、关键点检测
人工智能·算法·yolo·目标检测·计算机视觉·视觉检测