Reorder List

Find middle → Reverse second half → Merge alternately

Read Here
Step0 / 29
PhaseFind Middle
Nodes5
Chain[1→2→3→4→5]
Back To Linked List

Reorder List (Python)

1class Solution:
def reorderList(self, head):
3 if not head or not head.next:
......
8 while fast.next and fast.next.next:
9 slow = slow.next
10 fast = fast.next.next
11
......
13 prev, curr = None, slow.next
14 slow.next = None
15 while curr:
16 tmp = curr.next
17 curr.next = prev
18 prev = curr
19 curr = tmp
......
21 # Phase 3: Merge two halves
22 p1, p2 = head, prev
23 while p2:
24 p1_next, p2_next = p1.next, p2.next
25 p1.next = p2
26 p2.next = p1_next
27 p1 = p1_next
28 p2 = p2_next
Current Line (2): Method Signature

Reorder List Visualizer

Start

Step

0 / 29

Phase

Find Middle

Nodes

5

null1next2next3next4next5nextslowfast

Reorder Progress

Current Phase

Find Middle

Reordered Chain

12345
Find Middle
Reverse Half
Merge/Interleave
Done
Press Next to begin.

Pointer State

slow1
fast1

Why This Step Matters

Both slow and fast start at head. fast moves twice as fast.

Current Action

Initialize: slow = 1, fast = 1

Step Explanation

Start

Initialize Pointers

Set slow and fast pointers both to head. We'll use slow/fast to find the midpoint of the list.

  • > Phase: Find Middle
  • > slow and fast both start at head.
  • > slow moves 1 step at a time; fast moves 2 — when fast hits the end, slow is at the middle.
Unvisited
Current (slow/p1)
Prev
Fast / p2 / tmp
Reversed
Done / Merged