📘
Reorder List
MediumLinked List
Given a list L: L0 → L1 → … → Ln-1 → Ln, reorder it to: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → …
Output the reordered list as space-separated values.
Example:
Input:
1,2,3,4
Output:
1 4 2 3
Reasoning:
- The input list is split into two parts: the first half and the second half in reverse order.
- The first half of the list is
1, 2and the second half in reverse order is4, 3. - The two halves are then merged in an alternating manner:
1from the first half,4from the second half,2from the first half, and3from the second half. - The final output is the merged list as space-separated values:
1 4 2 3.
Constraints:
- 1 <= number of nodes <= 5 * 10^4
- 1 <= Node.val <= 1000
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.