单向链表利用快慢指针
/** * 单链表的中点 */ 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 }
以自己现在的努力程度,还没有资格和别人拼天赋