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
}
相关推荐
TracyCoder1231 小时前
LeetCode Hot100(19/100)——206. 反转链表
算法·leetcode
踩坑记录2 小时前
leetcode hot100 94. 二叉树的中序遍历 easy 递归 dfs
leetcode
醉颜凉4 小时前
【LeetCode】打家劫舍III
c语言·算法·leetcode·树 深度优先搜索·动态规划 二叉树
达文汐4 小时前
【困难】力扣算法题解析LeetCode332:重新安排行程
java·数据结构·经验分享·算法·leetcode·力扣
一匹电信狗4 小时前
【LeetCode_21】合并两个有序链表
c语言·开发语言·数据结构·c++·算法·leetcode·stl
User_芊芊君子4 小时前
【LeetCode经典题解】搞定二叉树最近公共祖先:递归法+栈存路径法,附代码实现
算法·leetcode·职场和发展
培风图南以星河揽胜4 小时前
Java版LeetCode热题100之零钱兑换:动态规划经典问题深度解析
java·leetcode·动态规划
算法_小学生4 小时前
LeetCode 热题 100(分享最简单易懂的Python代码!)
python·算法·leetcode
执着2594 小时前
力扣hot100 - 234、回文链表
算法·leetcode·链表
熬夜造bug4 小时前
LeetCode Hot100 刷题路线(Python版)
算法·leetcode·职场和发展