快慢指针停下时慢的在哪

👁️ 0 人浏览 💬 0 人评论 ❤️ 添加收藏

运行下面这段程序(链上是四个人,没有环):

class Node:
    def __init__(self, name):
        self.name = name
        self.next = None

def build(names):
    head = None
    for x in reversed(names):
        nd = Node(x)
        nd.next = head
        head = nd
    return head

head = build(["阿岚", "小满", "阿泰", "南风"])
slow = head
fast = head
while fast is not None and fast.next is not None:
    slow = slow.next
    fast = fast.next.next
print(slow.name)
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论