Reorder List
Rewire an acyclic list in place from L0,L1,...,Ln to L0,Ln,L1,Ln-1,... . Return nothing; the judge inspects the original head after mutation.
Example 1
head = [1,2,3,4,5][1,5,2,4,3]Explanation
Alternate front and back: 1,5,2,4, then middle node 3.
Example 2
head = [1,2,3,4][1,4,2,3]Explanation
Even length alternates 1,4,2,3 with no separate middle node.
Example 3
head = [7][7]Explanation
The single node needs no rewiring.
Constraints
- 1 <= number of nodes <= 50000
- Do not alter node values
Function contract
reorderListArguments: listSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[1,2,3,4,5]