def MeetingNode(self, pHead):
if not pHead:
return None
pSlow = pHead.next #定义一个慢指针2
pFast = pSlow.next#定义一个快指针3
while pSlow != pFast : #判断快慢指针是否相等
pSlow = pSlow.next
pFast=pFast.next.next
if pFast==None:
break
return pSlow,pFast
当链表中没有环时,pFast.next.next最后会变成None,但是代码中没有判断pFast.next.next是否为空的条件,因此我在代码中加入了判断条件
if pFast==None:
break