Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@ck0712

Description

@ck0712
Issue body actions
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.