Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Leetcode';非类型';对象没有属性';下一个';_Python_Linked List - Fatal编程技术网

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
时,将获得该错误

当您到达列表尾部(最后一个节点)时,
节点。下一个
将是
,因此您需要处理此情况。请发布完整错误和实际错误。您当前的代码不会引发任何错误,它只是定义了一个类。。。