# 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