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

题目:

题解:

Go 复制代码
func jump(nums []int) int {
    length := len(nums)
    end := 0
    maxPosition := 0
    steps := 0
    for i := 0; i < length - 1; i++ {
        maxPosition = max(maxPosition, i + nums[i])
        if i == end {
            end = maxPosition
            steps++
        }
    }
    return steps
}

func max(x, y int) int {
    if x > y {
        return x
    }
    return y
}
相关推荐
CoderYanger2 小时前
优选算法-栈:67.基本计算器Ⅱ
java·开发语言·算法·leetcode·职场和发展·1024程序员节
夏鹏今天学习了吗2 小时前
【LeetCode热题100(72/100)】前 K 个高频元素
leetcode
百***48074 小时前
【Golang】slice切片
开发语言·算法·golang
q***92514 小时前
Windows上安装Go并配置环境变量(图文步骤)
开发语言·windows·golang
墨染点香4 小时前
LeetCode 刷题【172. 阶乘后的零】
算法·leetcode·职场和发展
做怪小疯子4 小时前
LeetCode 热题 100——链表——反转链表
算法·leetcode·链表
做怪小疯子6 小时前
LeetCode 热题 100——矩阵——旋转图像
算法·leetcode·矩阵
sin_hielo7 小时前
leetcode 2435
数据结构·算法·leetcode
稚辉君.MCA_P8_Java10 小时前
Gemini永久会员 Java动态规划
java·数据结构·leetcode·排序算法·动态规划
小白程序员成长日记10 小时前
2025.11.23 力扣每日一题
算法·leetcode·职场和发展