Golang | Leetcode Golang题解之第330题按要求补齐数组

题目:

题解:

Go 复制代码
func minPatches(nums []int, n int) (patches int) {
    for i, x := 0, 1; x <= n; {
        if i < len(nums) && nums[i] <= x {
            x += nums[i]
            i++
        } else {
            x *= 2
            patches++
        }
    }
    return
}
相关推荐
Dream it possible!几秒前
LeetCode 面试经典 150_二分查找_搜索二维矩阵(112_74_C++_中等)
leetcode·面试·矩阵
求梦8208 分钟前
【力扣hot100题】缺失的第一个正数(12)
数据结构·算法·leetcode
黎雁·泠崖23 分钟前
二叉树实战进阶全攻略:从层序遍历到OJ题深度解析
c语言·数据结构·leetcode
千金裘换酒25 分钟前
LeetCode 回文链表
算法·leetcode·链表
老鼠只爱大米29 分钟前
LeetCode算法题详解 283:移动零
算法·leetcode·双指针·快慢指针·移动零·move zeroes
天远云服31 分钟前
Go语言高并发实战:集成天远多头借贷行业风险版API构建实时风控引擎
大数据·开发语言·golang·iphone
踩坑记录39 分钟前
leetcode hot100 最长连续子序列 哈希表 medium
leetcode
raoxiaoya40 分钟前
cloudwego - eino 使用教程
人工智能·golang
zhengxianyi5151 小时前
yudao-ui-go-view路由同时支持history及hash
ui·golang·哈希算法
橘颂TA1 小时前
【剑斩OFFER】算法的暴力美学——力扣:1047 题:删除字符串中的所有相邻重复项
c++·算法·leetcode·职场和发展·结构于算法