text: /**
   * Linked List Cycle II
   *
   * Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
   *
   * Note: Do not modify the linked list.
   *
   * Follow up:
   * Can you solve it without using extra space?
   */
  
  /**
   * Definition for singly-linked list.
   * function ListNode(val) {
   *     this.val = val;
   *     this.next = null;
   * }
   */
  
  /**
   * @param {ListNode} head
   * @return {ListNode}
   */
  const detectCycle = head => {
    let slow = head;
    let fast = head;
  
    while (fast && fast.next) {
      slow = slow.next;
      fast = fast.next.next;
  
      if (slow === fast) {
        slow = head;
  
        while (slow !== fast) {
          slow = slow.next;
          fast = fast.next;
        }
  
        return slow;
      }
    }
  
    return null;
  };
  
  export { detectCycle };
  