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
}
相关推荐
Nil2082 小时前
leetcode 55跳跃游戏
算法·leetcode·游戏
longlongzihan2 小时前
LeetCode 128. 最长连续序列 —— 从排序到哈希集合
数据结构·c++·算法·leetcode·排序算法·哈希表
谢亮_vipxieliang3 小时前
Go defer、panic与recover核心知识点
开发语言·后端·golang
谢亮_vipxieliang4 小时前
Go基础数据类型全解
开发语言·后端·golang
圣保罗的大教堂4 小时前
leetcode 3302. 字典序最小的合法序列 中等
leetcode
谢亮_vipxieliang5 小时前
Go 接口设计原则核心知识点
开发语言·ios·golang
Logic1015 小时前
C语言/数据结构位运算题解:异或XOR找出英雄队伍中的“独特战斗力“——只出现一次的数字
c语言·数据结构·数组·位运算·时间复杂度·算法题·异或性质
谢亮_vipxieliang5 小时前
Go 结构体与方法集核心知识点
java·开发语言·golang
Cccp.1235 小时前
【leetcode】(九)哈希函数与哈希表
数据结构·leetcode·哈希算法
xieliyu.5 小时前
LeetCode 1419 数青蛙:状态模拟求最少青蛙数量|Java 题解
java·算法·leetcode