Python solution


  • 0
    P
    class Solution(object):
        def plusOne(self, digits):
            
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            if len(digits)==0:
                return []
            i=len(digits)-1
            digits[i]+=1
            while digits[i]>=10 and i>0:
                digits[i]=0
                digits[i-1]+=1
                i-=1
            if digits[0]>=10:
                digits[0]=0
                digits.insert(0,1)
            return digits

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.