# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def addTwoNumbers(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
ret = ListNode(0)
pointer = ret
while True:
if l1 is None and l2 is None:
break
v1 = l1.val if l1 is not None else 0
v2 = l2.val if l2 is not None else 0
pointer.val += v1 + v2
if pointer.val >= 10:
pointer.next = ListNode(1)
pointer.val -= 10
if l1 is not None:
l1 = l1.next
if l2 is not None:
l2 = l2.next
if l1 is None and l2 is None:
break
if pointer.next is None: # 没有进位
pointer.next = ListNode(0)
pointer = pointer.next
return ret