From ed7f6b1324ff7e84a4900dd0be81deab5182a73f Mon Sep 17 00:00:00 2001 From: power17 <1410837981@qq.com> Date: Tue, 5 Sep 2023 15:39:01 +0800 Subject: [PATCH] Update LinkedListAlgo.js --- javascript/07_linkedlist/LinkedListAlgo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/07_linkedlist/LinkedListAlgo.js b/javascript/07_linkedlist/LinkedListAlgo.js index 77695c99..32ee6d14 100644 --- a/javascript/07_linkedlist/LinkedListAlgo.js +++ b/javascript/07_linkedlist/LinkedListAlgo.js @@ -169,7 +169,7 @@ class LinkedList { findMiddleNode() { let fast = this.head let slow = this.head - while (fast.next !== null && fast.next.next !== null) { + while (fast.next !== null && fast.next !== null && fast.next.next !== null) { fast = fast.next.next slow = slow.next } @@ -247,4 +247,4 @@ let sortedList = mergeSortedLists(sortedList1.head.next, sortedList2.head.next) while (sortedList !== null) { console.log(sortedList.element) sortedList = sortedList.next -} \ No newline at end of file +}