Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

剑指offer中倒数第三题出现的问题:程序可以运行,但在牛客网上报错 'NoneType' object has no attribute 'next' 不知道为什么?? #10

Open
ck0712 opened this issue Sep 30, 2019 · 0 comments

Comments

@ck0712
Copy link

ck0712 commented Sep 30, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant