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
}
相关推荐
Tony Bai6 小时前
Go 安全新提案:runtime/secret 能否终结密钥残留的噩梦?
java·开发语言·jvm·安全·golang
小武~7 小时前
Leetcode 每日一题C 语言版 -- 45 jump game ii
c语言·算法·leetcode
leoufung11 小时前
用 DFS 拓扑排序吃透 LeetCode 210:Course Schedule II
算法·leetcode·深度优先
Swift社区12 小时前
LeetCode 443. 压缩字符串
leetcode·职场和发展·蓝桥杯
ada7_12 小时前
LeetCode(python)——543.二叉树的直径
数据结构·python·算法·leetcode·职场和发展
sprintzer12 小时前
11.26-12.05力扣栈刷题
算法·leetcode·职场和发展
sin_hielo13 小时前
leetcode 3578
数据结构·算法·leetcode
前端小白在前进13 小时前
力扣刷题:无重复字符的最长子串
算法·leetcode·职场和发展
卿雪13 小时前
Redis 线程模型:Redis为什么这么快?Redis为什么引入多线程?
java·数据库·redis·sql·mysql·缓存·golang
好易学·数据结构14 小时前
可视化图解算法72:斐波那契数列
数据结构·算法·leetcode·动态规划·力扣·牛客网