# 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:
ans=ListNode(0) #dummy head
tmp=ans
left=0
while l1 or l2:
x=l1.val if l1 !=None else 0
y=l2.val if l2 !=None else 0
sum=x+y+left
node=ListNode(sum%10)
left=sum//10
tmp.next=node
tmp=tmp.next
l1=l1.next if l1 !=None else l1
l2=l2.next if l2 !=None else l2
if left>0:
tmp.next=ListNode(left)
return ans.next