/** * 单链表的中点 */ const middleNode = (node = linkList) => { let slow = node, fast = node; while(fast && fast.next){ slow = slow.next fast = fast.next.next } return slow.value } /** * 判断链表是否包含环 */ const hasCycle = (node = linkList) => { let slow = node, fast = node; while(fast && fast.next){ slow = slow.next fast = fast.next.next if(fast === slow){ return true } } return false }
标签:node,slow,return,单向,fast,next,链表,指针 From: https://www.cnblogs.com/zhenjianyu/p/17077203.html