快慢指针停下时慢的在哪
运行下面这段程序(链上是四个人,没有环):
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)
全部评论