Golang | Leetcode Golang题解之第66题加一

题目:

题解:

Go 复制代码
func plusOne(digits []int) []int {
    n := len(digits)
    for i := n - 1; i >= 0; i-- {
        if digits[i] != 9 {
            digits[i]++
            for j := i + 1; j < n; j++ {
                digits[j] = 0
            }
            return digits
        }
    }
    // digits 中所有的元素均为 9

    digits = make([]int, n+1)
    digits[0] = 1
    return digits
}
相关推荐
pixcarp6 小时前
知识库系统的内容资产闭环怎么设计
服务器·数据库·后端·golang
张忠琳9 小时前
【Go 1.26.4】Golang Select 深度解析
开发语言·后端·golang
提笔了无痕11 小时前
如何用Go实现整套RAG流程
开发语言·后端·golang
一只齐刘海的猫11 小时前
【Leetcode】找到字符串中所有字母异位词
算法·leetcode·职场和发展
wlsh1511 小时前
Go 错误处理
golang
geovindu12 小时前
go: Generators Pattern
开发语言·后端·设计模式·golang·生成器模式
凌波粒13 小时前
LeetCode--108.将有序数组转换为二叉搜索树(二叉树)
算法·leetcode·职场和发展
兰令水13 小时前
leecodecode【面试150】【2026.6.13打卡-java版本】
java·算法·leetcode
临沂堇13 小时前
刷题日志 | Leetcode Hot 100 哈希
算法·leetcode·哈希算法
Navigator_Z16 小时前
LeetCode //C - 1096. Brace Expansion II
c语言·算法·leetcode