Python Leetcode';非类型';对象没有属性';下一个';
我正在解决这个问题,但我遇到了一个错误:Python Leetcode';非类型';对象没有属性';下一个';,python,linked-list,Python,Linked List,我正在解决这个问题,但我遇到了一个错误: AttributeError: 'NoneType' object has no attribute 'next' 有人能帮我指出正确的方向吗 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: d
AttributeError: 'NoneType' object has no attribute 'next'
有人能帮我指出正确的方向吗
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
while (True):
headA = headA.next # advance '1' step in list_A {this is the error line}
if (headA == headB): # check for equality
return headA
headB = headB.next # advance '1' step in list_B
当您到达链表的末尾时,即
headA
为None
时,将获得该错误 当您到达列表尾部(最后一个节点)时,节点。下一个
将是无
,因此您需要处理此情况。请发布完整错误和实际错误。您当前的代码不会引发任何错误,它只是定义了一个类。。。