defaddTwoNumbers(l1: ListNode, l2: ListNode) -> ListNode: head = result = ListNode() carry = False while l1 or l2: val = 0 if l1: val += l1.val l1 = l1.next if l2: val += l2.val l2 = l2.next if carry: val+=1#注意在python中没有自增和自减运算符! carry = (val >= 10) val = val % 10; result.next = ListNode(val) result = result.next if carry: result.next = ListNode(1) return head.next