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
}
相关推荐
py有趣2 小时前
力扣热门100题之接雨水
算法·leetcode
不会写DN3 小时前
构建一个抗揍的 Go TCP 聊天服务:异常兜底与防御性编程实践
tcp/ip·golang·php
不会写DN5 小时前
Go中如何跨语言实现传输? - GRPC
开发语言·qt·golang
py有趣6 小时前
力扣热门100题之合并区间
算法·leetcode
派大星~课堂6 小时前
【力扣-138. 随机链表的复制 ✨】Python笔记
python·leetcode·链表
cpp_25016 小时前
P10108 [GESP202312 六级] 闯关游戏
数据结构·c++·算法·动态规划·题解·洛谷·gesp六级
py有趣6 小时前
力扣热门100题之最小覆盖子串
算法·leetcode
北顾笙9807 小时前
day15-数据结构力扣
数据结构·算法·leetcode
人道领域7 小时前
【LeetCode刷题日记:24】两两交换链表
算法·leetcode·链表
北顾笙9807 小时前
day16-数据结构力扣
数据结构·算法·leetcode