### 递归实现

class ListNode:

    def init(self, val=0, next=None):

        self.val = val

        self.next = next

        

class Solution:

    def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:

        # 都结束了末尾节点就为None

        if l1  None and l2  None:

            return None

        # 补齐 [9,9,9,9] + [9] 的情况

        if l1 == None:

            l1=ListNode(0)

        if l2 == None:

            l2= ListNode(0)

        # 值加

        sum = l1.val + l2.val

        if sum >= 10:

            # 判断[9] + [9]的情况,进位

            if l1.next == None:

                l1.next = ListNode(0)

            l1.next.val +=1

            return ListNode(sum % 10 ,self.addTwoNumbers(l1.next, l2.next))

        return ListNode(sum, self.addTwoNumbers(l1.next, l2.next))