美文网首页
66. Plus One

66. Plus One

作者: a_void | 来源:发表于2016-09-08 12:04 被阅读0次

    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):
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            def f(index):
                if index < 0:
                    digits[0:0] = [1]
                elif digits[index] < 9:
                    digits[index] += 1
                else:
                    digits[index] = 0
                    return f(index - 1)
                return digits
            return f(len(digits)-1)
    

    相关文章

      网友评论

          本文标题:66. Plus One

          本文链接:https://www.haomeiwen.com/subject/dnusettx.html