两数相加
# 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:
head = ListNode(0)
node = head
carry = 0
while l1 or l2:
x = l1.val if l1 else 0
y = l2.val if l2 else 0
summ = x + y + carry
carry = summ // 10
node.next = ListNode(summ%10)
if l1:
l1 = l1.next
if l2:
l2 = l2.next
node = node.next
if carry != 0:
node.next = ListNode(1)
return head.next