← Visualizers
Fast & Slow Pointers LeetCode 876

Middle of the Linked List / visualized

Find the middle node in one pass, no length counting, no second pass. Slow ๐Ÿข moves one node at a time, fast ๐Ÿ‡ moves two. When fast runs out of road, slow is standing on the middle.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java ยท running line

slow ๐Ÿข fast ๐Ÿ‡ middle node null / end
O(n) time ยท O(1) space  ยท  for even-length lists this convention returns the second middle โ€” the loop condition fast != null && fast.next != null is why.