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
}
相关推荐
F_D_Z12 分钟前
最长连续序列(Longest Consecutive Sequence)
数据结构·算法·leetcode
flashlight_hi2 小时前
LeetCode 分类刷题:199. 二叉树的右视图
javascript·算法·leetcode
LYFlied2 小时前
【每日算法】LeetCode 46. 全排列
前端·算法·leetcode·面试·职场和发展
小信啊啊2 小时前
Go语言数组与切片的区别
开发语言·后端·golang
云霄IT3 小时前
docker使用教程之部署第一个go项目
docker·容器·golang
LYFlied3 小时前
【每日算法】131. 分割回文串
前端·数据结构·算法·leetcode·面试·职场和发展
长安er3 小时前
LeetCode 300/152/416/32 动态规划进阶题型总结(最长递增子序列→最长有效括号)
数据结构·算法·leetcode·动态规划·剪枝
季远迩3 小时前
LeetCode 热题 100 Python3易懂题解(更新中)
算法·leetcode·哈希算法
Tony Bai4 小时前
Go 1.26 新特性前瞻:从 Green Tea GC 到语法糖 new(expr),性能与体验的双重进化
开发语言·后端·golang
Dream it possible!4 小时前
LeetCode 面试经典 150_回溯_组合(99_77_C++_中等)
c++·leetcode·面试·回溯