Leetcode 'NoneType' 对象没有属性 'next'



我正在解决这个问题,但出现错误:

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

当您到达链表的末尾时,即当headANone时,就会获得错误。

相关内容

  • 没有找到相关文章

最新更新