Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

problem from LeetCode 66


In [22]:
# Input
digits = [2,9,9]

In [23]:
def plusOne(digits):
    """
    :type digits: List[int]
    :rtype: List[int]
    """
    new = ''
    for i in digits:
        new += str(i)
    new = str(int(new)+1)

    result = []
    for j in new:
        result.append(int(j))
    return result

In [24]:
# Output
plusOne(digits)


Out[24]:
[3, 0, 0]