Skip to content

判断一个链表是否有环,如果有的话返回第一个进环的节点.py #12

@GitMsw

Description

@GitMsw

应该是:if fast == None or slow == None: 才返回None吧?
而且是返回return fast.next这个才是第一个进环的结点,直接返回fast是前一个结点

我写了测试发现的,楼主看下
3 <main.Node object at 0x000001E414C26080>
4 <main.Node object at 0x000001E414C260B8>
5 <main.Node object at 0x000001E414C26048>
3 <main.Node object at 0x000001E414C26080>
4 <main.Node object at 0x000001E414C260B8>
5 <main.Node object at 0x000001E414C26048>
3 <main.Node object at 0x000001E414C26080>
4 <main.Node object at 0x000001E414C260B8>

结果= <main.Node object at 0x000001E414C26080>

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