# 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:
if l1 is None:
return l2
if l2 is None:
return l1
head = ListNode(-1)
cur,c = head,0
while(l1 is not None or l2 is not None):
p1 = l1.val if l1 is not None else 0
p2 = l2.val if l2 is not None else 0
cur_val = p1 + p2 + c
res = cur_val%10
c = cur_val//10
# print(cur_val, c)
cur.next = ListNode(res)
cur = cur.next
if l1 is not None: l1 = l1.next
if l2 is not None: l2 = l2.next
if c == 1:
cur.next = ListNode(c)
cur = cur.next
return head.next
# while(head.next is not None):
# print(head.next.val)
# head = head.next