|
发表于 2024-3-20 21:24:31
|
显示全部楼层
@FishC
# Definition for singly-linked list.
# 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]:
while l1 or l2:
total = l1.val + l2.val if total >= 10:
next1 = 1
else:
next1 = 0
l1 = l1.next
l2 = l2.next
new = ListNode()
cur = new
new.val = total % 10
return new
为什么报错AttributeError: 'NoneType' object has no attribute 'val' |
|