这个有点像垃圾回收机制里的标记清除,遍历过就加个标记,如果标记过的就是环的入口

function ListNode(x){ this.val = x; this.next = null; }

function EntryNodeOfLoop(pHead) { // write code here while (pHead != null) {

    if (pHead.flag == true) {
        return pHead;
    }
    pHead.flag = true;
    pHead = pHead.next;
}
 

} module.exports = { EntryNodeOfLoop : EntryNodeOfLoop };