题解 | #链表中环的入口结点#
链表中环的入口结点
https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
/*function ListNode(x){ this.val = x; this.next = null; }*/ function EntryNodeOfLoop(pHead) { // write code here const set = new Set(); let cur = pHead; while(cur){ if(set.has(cur)){ return cur } set.add(cur) cur = cur.next; } return null; } module.exports = { EntryNodeOfLoop : EntryNodeOfLoop };
解题思路:判断节点是否重复出现,出现的第一个便是入口
#链表环#