给出一个链表,若其中包含环,请找出该链表的环的入口节点,否则输出null
var findNode = (head)=>{if(head.next == null || head == null){return null}var slow = headvar fast = headwhile(fast != slow){if(fast == null || fast.next == null){return null}fast = fast.next.nextslow = slow.next}// 环的长度let length = 1let temp = slowslow = slow.nextif(slow != temp){length++}// 找到环的位置fast =slow = headwhile(length-->0){fast = fast.next}while(fast == slow){slow = slow.nextfast = fast.next}return slow}
