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
}
相关推荐
踩坑记录3 小时前
leetcode hot100 2.两数相加 链表 medium
leetcode·链表
历程里程碑5 小时前
滑动窗口---- 无重复字符的最长子串
java·数据结构·c++·python·算法·leetcode·django
TracyCoder1237 小时前
LeetCode Hot100(18/100)——160. 相交链表
算法·leetcode
放荡不羁的野指针8 小时前
leetcode150题-滑动窗口
数据结构·算法·leetcode
女王大人万岁9 小时前
Go标准库 io与os库详解
服务器·开发语言·后端·golang
TracyCoder1239 小时前
LeetCode Hot100(13/100)——238. 除了自身以外数组的乘积
算法·leetcode
Anastasiozzzz9 小时前
LeetCode Hot100 215. 数组中的第K个最大元素
数据结构·算法·leetcode
让我上个超影吧9 小时前
【力扣76】最小覆盖子串
算法·leetcode·职场和发展
求梦82011 小时前
【力扣hot100题】合并两个有序链表(22)
算法·leetcode·链表
女王大人万岁11 小时前
Go语言time库核心用法与实战避坑
服务器·开发语言·后端·golang