/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function EntryNodeOfLoop(head) {
    if (head === null || head.next === null) return null;
    
    let fast = head;
    let slow = head;
 
    while (fast && fast.next) {
       fast = fast.next.next;
       slow = slow.next;
       if (fast === slow) break;
    }
    
    if (fast !== slow) return null; // hasCycle
    
    fast = head;
    
    while (fast !== slow) {
        fast = fast.next;
        slow = slow.next
    }
    
    return fast
}
module.exports = {
    EntryNodeOfLoop : EntryNodeOfLoop
};