text: # Definition for singly-linked list.
  # class ListNode:
  #     def __init__(self, val=0, next=None):
  #         self.val = val
  #         self.next = next
  class Solution:
      def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
          dummy = ListNode()
          cur = dummy
          carry = 0
          while l1 or l2:
              val = carry
              if l1:
                  val += l1.val
                  l1 = l1.next
              if l2:
                  val += l2.val
                  l2 = l2.next
              if val >= 10:
                  val -= 10
                  carry = 1
              else:
                  carry = 0
              cur.next = ListNode(val)
              cur = cur.next
          if carry:
              cur.next = ListNode(1)
          return dummy.next
  