*ListNode生成/调用/next
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
l3h = ListNode(0)
l3 = l3h
tempSum = 0
while l1 or l2 or tempSum:
if l1:
tempSum += l1.val
l1 = l1.next
if l2:
tempSum += l2.val
l2 = l2.next
sumResult = tempSum%10
l3.next = ListNode(sumResult)
l3 = l3.next
tempSum = tempSum//10
return l3h.next
Accepted | 76 ms | 13.8 MB | python3 |