My simple Python solution(beats 92.69%)


  • 0
    J
    class Solution(object):
        def plusOne(self, digits):
            decent = 1
            for i in range(1, len(digits)+1):
                s = decent + digits[-i]
                if s >= 10:
                    digits[-i] = s % 10
                    decent = 1
                else:
                    digits[-i] = s
                    decent = 0
                    break
            if decent == 1:
                digits = [1] + digits
            return digits
    

Log in to reply
 

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