题解 | #链表中环的入口结点#
链表中环的入口结点
https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
/*function ListNode(x){ this.val = x; this.next = null; }*/ function EntryNodeOfLoop(pHead) { // write code here if (pHead === null) return null let slowNode = pHead let fastNode = pHead while (fastNode) { slowNode = slowNode.next fastNode = fastNode.next if (fastNode === null) return null fastNode = fastNode.next if (fastNode === slowNode) break } if (fastNode === null) return null fastNode = pHead while (fastNode !== slowNode) { fastNode = fastNode.next slowNode = slowNode.next } return slowNode } module.exports = { EntryNodeOfLoop : EntryNodeOfLoop };