Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 14, 2023
1 parent 10e82c1 commit cb19a40
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions coding_interviews/algoexpert/middle-node/middle-node-slow-fast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Runtime: O(N), N = number of nodes in the linked list
// Space: O(1)

function middleNode(linkedList) {
let fast = linkedList;
let slow = linkedList;

while (fast && fast.next) {
fast = fast.next.next;
slow = slow.next;
}

return slow;
}

0 comments on commit cb19a40

Please sign in to comment.