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
}
相关推荐
Tisfy20 小时前
LeetCode 3498.字符串的反转度:一次遍历
leetcode·字符串·题解·遍历
a1879272183120 小时前
【算法】树(二):队列与祖先——BFS 骨架三配件、短路透传与合流
算法·leetcode·二叉树··bfs·算法讲解·树遍历
Navigator_Z1 天前
LeetCode //C - 1254. Number of Closed Islands
c语言·算法·leetcode
0+1111 天前
算法 --二分查找
c++·算法·leetcode
圣保罗的大教堂1 天前
leetcode 1674. 使数组互补的最少操作次数 中等
leetcode
指尖的爷1 天前
ARM 架构 Ubuntu(RK3588/aarch64)go开发环境安装手册
ubuntu·架构·golang
名字还没想好☜1 天前
Go 实现指数退避重试:context 取消、抖动 jitter 与什么时候别重试
后端·golang·go
kukubuzai1 天前
双指针系列二--末尾篇(3道题)
c++·算法·leetcode
Casbin开源社区1 天前
OpenAgent 详解:单二进制自托管 AI Agent 平台,30+ 模型接入、RAG 知识库、MCP 工具调用与 Casbin 工具权限
人工智能·golang·开源
漂流瓶jz2 天前
UVA-1442 洞穴 题解答案代码 算法竞赛入门经典第二版
c++·算法·题解·aoapc·算法竞赛入门经典·uva