Finish when the second half is emptyThe merge guard fails at second = null. The in-place list is 1->5->2->4->3->null.
1→5→2→4→3
result1->5->2->4->3
Recognize it
Use it when nodes must alternate from the front and back of a singly linked list without an auxiliary array or stack.
Keep true
The midpoint scan keeps fast twice as far along; reversal preserves a reversed prefix plus untouched suffix; merging preserves the final alternating prefix and two unconsumed chains.
Reuse it
Complex list transforms become safe compositions of small invariants: locate a boundary, detach, reverse with a saved route, then splice only after saving both continuations.
Read it this way: For 1->2->3->4->5, set slow = 1 and fast = 1. Both fast.next and fast.next.next exist. Step through the frames to watch the state change. The last frame shows the answer or the stopping condition.
Pattern: Find middle, reverse second half, then merge.
Simple idea: This problem combines three linked-list moves. Slow and fast pointers find
the middle. Reverse the second half. Alternate nodes from the two halves.
def reorder_list(head: ListNode | None) -> None: if head is None or head.next is None: return slow = head fast = head while fast.next and fast.next.next: slow = slow.next fast = fast.next.next second = slow.next slow.next = None previous = None while second: next_node = second.next second.next = previous previous = second second = next_node first = head second = previous while second: first_next = first.next second_next = second.next first.next = second second.next = first_next first = first_next second = second_next
Cost:O(n) time and O(1) space.
The platform supplies ListNode with val and next; this snippet assumes that definition.