# Definition for singly-linked list. # class ListNode: #     def __init__(self, x): #         self.val = x #         self.next = None class Solution:     def detectCycle(self, head: ListNode) -> ListNode:         if not head:             return None         slow,fast = head,head         mixed= None         while fast.next and fast.next.next:             fast = fast.next.next             slow = slow.next             if fast == slow:                 slow = head                 while fast != slow:                     fast = fast.next                     slow = slow.next                 return slow         return None 封贴,这题目的输出也 不说清楚,我以为要返回相交节点的位置呢😥
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务