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 +}