Middle of the Linked List
LeetCode 876 • Easy • Linked Lists
Input: head = [1, 2, 3, 4, 5] → Output: node 3
Return the middle node. If two middle nodes, return the second middle.
TimeO(n)single pass
SpaceO(1)only two pointers
Iterations: 0
Slow: —
Fast: —
Slow (tortoise)
Fast (hare)
Middle
Slow
—
Fast
—
Result
pending
Ready
Press Play to watch the fast & slow pointer technique find the middle, or Step to advance one operation.
Slow moves 1 step, fast moves 2 steps. When fast reaches the end, slow is at the middle.
Slow moves 1 step, fast moves 2 steps. When fast reaches the end, slow is at the middle.