Skip to content

Reorder List

MediumLinked List
Decode it first. Clues, constraints, pattern and plan before any code.

Given the head of a linked list L0 -> L1 -> ... -> Ln, rearrange it in place into

L0 -> Ln -> L1 -> Ln-1 -> L2 -> Ln-2 -> ...

alternating one node from the front with one from the back. Change the next pointers, not the values. Return nothing; the tests look at the list starting from the original head.

1 -> 2 -> 3 -> 4        →  1 -> 4 -> 2 -> 3
1 -> 2 -> 3 -> 4 -> 5   →  1 -> 5 -> 2 -> 4 -> 3

Constraints

  • 0 <= number of nodes <= 5 * 10^4
  • 1 <= Node.val <= 1000