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
}
相关推荐
zenithdev18 小时前
fastcache:为 Go 设计的低 GC 压力内存缓存
开发语言·其他·缓存·golang
北冥you鱼12 小时前
Go语言sync包在区块链开发中的数据同步实践
golang·centos·区块链
tachibana213 小时前
hot100 排序链表(148)
java·数据结构·算法·leetcode·链表
不能跑的代码不是好代码14 小时前
二叉树从基础概念到LeetCode实战
算法·leetcode
凯瑟琳.奥古斯特14 小时前
二分查找解力扣1011最优运载能力
开发语言·c++·算法·leetcode·职场和发展
布朗克16815 小时前
Go 入门到精通-13-指针与内存
开发语言·c++·golang·指针与内存
xurime1 天前
Excelize 开源十周年,发布 2.11.0 版本
golang·开源·github·excel·导出·导入·excelize·基础库
YuK.W1 天前
Leetcode100: 70.爬楼梯、118.杨辉三角、198.打家劫舍
java·算法·leetcode
旖-旎1 天前
《LeetCode 64 最小路径和 || LeetCode 174 地下城游戏》
c++·算法·leetcode·动态规划
凯瑟琳.奥古斯特1 天前
力扣1009补码解法C++实现
开发语言·c++·算法·leetcode·职场和发展