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
}
相关推荐
轮到我狗叫了40 分钟前
力扣.84柱状图中最大矩形 力扣.134加油站牛客.abb(hard 动态规划+哈希表)牛客.哈夫曼编码
算法·leetcode·职场和发展
想搞艺术的程序员2 小时前
Go Error 全方位解析:原理、实践、扩展与封装
开发语言·后端·golang
竹等寒2 小时前
Go红队开发—图形化界面
网络安全·golang·个人开发
熬了夜的程序员3 小时前
【LeetCode】99. 恢复二叉搜索树
算法·leetcode·职场和发展
Kent_J_Truman3 小时前
LeetCode Hot100 自用
算法·leetcode·职场和发展
还是码字踏实3 小时前
算法题种类与解题思路全面指南:基于LeetCode Hot 100与牛客Top 101
算法·leetcode
熬了夜的程序员5 小时前
【LeetCode】101. 对称二叉树
算法·leetcode·链表·职场和发展·矩阵
Kuo-Teng6 小时前
LeetCode 73: Set Matrix Zeroes
java·算法·leetcode·职场和发展