class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        head=cur=ListNode(0)
        carry=0
        while l1 or l2 or carry:
            tmp=carry
            if l1:
                tmp+=l1.val
                l1=l1.next
            if l2:
                tmp+=l2.val
                l2=l2.next
            if tmp>=10:
                tmp-=10
                carry=1
            else:
                carry=0
            tmp_node=ListNode(tmp)
            cur.next=tmp_node
            cur=cur.next
        return head.next