My "beating 89% Python solution"


  • 0
    X
    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        carry = (digits[-1] + 1) // 10
        digits[-1] = (digits[-1] + 1) % 10
        if not carry:
            return digits
            
        i = len(digits) - 2
        while i >= 0 and carry:
            n = digits[i] 
            digits[i] = (n + carry) % 10
            carry = (n + carry) // 10
            i -= 1
        return [carry] + digits if carry else digits

Log in to reply
 

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