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
}
相关推荐
玛丽莲茼蒿1 天前
Leetcode hot100 每日温度【中等】
算法·leetcode·职场和发展
样例过了就是过了1 天前
LeetCode热题100 分割等和子集
数据结构·c++·算法·leetcode·动态规划
北顾笙9801 天前
day38-数据结构力扣
数据结构·算法·leetcode
m0_629494731 天前
LeetCode 热题 100-----14.合并区间
数据结构·算法·leetcode
xin_nai1 天前
LeetCode热题100(Java)(5)普通数组
算法·leetcode·职场和发展
水蓝烟雨1 天前
3337. 字符串转换后的长度 II
算法·leetcode
_日拱一卒1 天前
LeetCode:226翻转二叉树
数据结构·算法·leetcode
踩坑记录1 天前
leetcode hot100 64. 最小路径和 medium 递归优化
leetcode·深度优先
lolo大魔王1 天前
Go语言的并发、协调创建和通信机制
开发语言·golang
样例过了就是过了1 天前
LeetCode热题100 最长有效括号
c++·算法·leetcode·动态规划