8 Lines Python Emulation


  • 0
    class Solution(object):
        def plusOne(self, digits):
            ans, idx, carry = [], len(digits) - 1, 1
            while idx >= 0:
                ans.append( (digits[idx] + carry) % 10)
                carry = (digits[idx] + carry) / 10
                idx -= 1
            if carry:
                ans.append(1)
            return ans[::-1]
    

Log in to reply
 

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