<gh_stars>0
# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        res = dummy = ListNode(0)
        carry = 0

        while l1 or l2:
            x = l1.val if l1 else 0
            y = l2.val if l2 else 0
            carry, nxt = divmod(x + y + carry, 10)
            dummy.next = ListNode(nxt)
            dummy = dummy.next

            l1 = l1.next if l1 else None
            l2 = l2.next if l2 else None

        if carry:
            dummy.next = ListNode(carry)

        return res.next

# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        res = dummy = ListNode(0)
        carry = 0

        while l1 or l2:
            x = l1.val if l1 else 0
            y = l2.val if l2 else 0
            carry, nxt = divmod(x + y + carry, 10)
            dummy.next = ListNode(nxt)
            dummy = dummy.next

            l1 = l1.next if l1 else None
            l2 = l2.next if l2 else None

        if carry:
            dummy.next = ListNode(carry)

        return res.next
# Definition for singly-linked list.