this.val = x;
this.next = null;
}*/
function EntryNodeOfLoop(pHead)
{
// write code here
//初始化:快指针fast指向头结点,慢指针slow指向头结点;
//让fast一次走两步,slow一次走一步,第一次相遇处,停止;
//然后让fast指向头结点,slow原地不动,让fast,slow每次走一步,当再次相遇,就是入口结点
let fast = pHead,slow = pHead
while(fast && fast.next){
fast = fast.next.next
slow = slow.next
if(fast === slow){
let fast1 = pHead
while(fast1 !== slow){
fast1 = fast1.next
slow = slow.next
}
return fast1
}
}
return null
}
module.exports = {
EntryNodeOfLoop : EntryNodeOfLoop
};