Simple Python solution

  • 0
    class Solution(object):
        def plusOne(self, head):
            carry = self._plusOne(head)
            if carry > 0:
                new_head = ListNode(carry)
       = head
                return new_head
            return head
        def _plusOne(self, head):
            if head is None:
                return 1
            carry = self._plusOne(
            carry, reminder = divmod(head.val + carry, 10)
            head.val = reminder
            return carry

Log in to reply

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