(node)
return slow
获取产生循环的那一段
获取产生循环的那一段
获取产生循环的那一段
def cycle(node):
    """获取产生循环的那一段"""
    slow, fast = node, node.next
    while slow != fast:
        if fast is None or fast.next is None:
            return None
        slow = slow.next
        fast = fast.next.next
    slow = node
    fast = fast.next
    while slow != fast:
        slow = slow.next
        fast = fast.next
    return slow
def cycle ( node ) : slow , fast = node , node . next while slow != fast : if fast is None or fast . next is None : return None slow = slow . next fast = fast . next . next slow = node fast = fast . next while slow != fast : slow = slow . next fast = fast . next return slow