题解 | #链表中环的入口结点#
链表中环的入口结点
https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function EntryNodeOfLoop(pHead)
{
// write code here
if (pHead === null || pHead.next === null) {
return null
}
let fast = pHead
let slow = pHead
while (fast) {
slow = slow.next
fast = fast.next.next
if (slow === fast) {
let p1 = pHead
while (slow !== p1) {
slow = slow.next
p1 = p1.next
}
return p1
}
}
return null
}
module.exports = {
EntryNodeOfLoop : EntryNodeOfLoop
};
SHEIN希音公司福利 318人发布
