You are given a singly linked list L: L0→L1→…→Ln-1→Ln. Reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…. You must do this in-place without altering node values. Example: Input: [1,2,3,4] Output: [1,4,2,3] Explanation: After ordering, 1→4→2→3. Pattern focus: Pointer Rewiring (split and merge).
head = ListNode
return ListNode
Example 1:
Input:
head = [1,2,3,4]
Output:
[1,4,2,3]
Explanation:
Reordered by weaving end nodes into front.