Plus One【leetcode】【89】【E】

Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.


class Solution(object):
    def plusOne(self, digits):
        l = len(digits)
        d = digits
        p = 1 #表示进位
       
        for i in range(l-1,-1,-1):
            res = d[i] + p
            if  res > 9:
                d[i] = (res-10)
                p = 1
            else:
                d[i] = res
                p = 0
        if p == 1:
            d = [1]+d
        return d
        """
        :type digits: List[int]
        :rtype: List[int]
        """
       


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Plus One【leetcode】【89】【E】

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭