text: 
  class ListNode(object):
      def __init__(self, x):
          self.val = x
          self.next = None
  
  
  class Solution(object):
      def detectCycle(self, head):
          """
          :type head: ListNode
          :rtype: ListNode
          """
          fast, slow = head, head
          while True:
              if not (fast and fast.next):
                  return
              fast, slow = fast.next.next, slow.next
              if fast == slow:
                  break
          fast = head
          while fast != slow:
              fast, slow = fast.next, slow.next
          return fast
  
  
  if __name__ == "__main__":
      solution = Solution()
      nodes = [ListNode(3), ListNode(2), ListNode(0), ListNode(4)]
      nodes[0].next = nodes[1]
      nodes[1].next = nodes[2]
      nodes[2].next = nodes[3]
      nodes[3].next = nodes[1]
      print(solution.detectCycle(nodes[0]))
  