A solution beats 95%


  • 0
    Z
    class Solution(object):
        def plusOne(self, digits):
            digits[-1]+=1
            for i in range(1,len(digits)+1):
                if i!=len(digits):
                    if digits[-i]>9:
                        digits[-i]=0
                        digits[-i-1]+=1
                    else: return digits
            if digits[0]>9:
                digits[0]=0
                digits.insert(0,1)
            return digits
    

    any suggestion would be appreciate


Log in to reply
 

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