52. Odd Even Linked List

Given a singly linked list. Reorder it so that all nodes with odd indices come first, then nodes with even indices. The relative order within each group must be preserved.
Example 1
Input: head = [2,1,3,5,6,4,7]
Output: [2,3,6,7,1,5,4]
Explanation: The relative order within the odd and even groups is preserved.
Example 2
Input: head = [1,2,3,4,5]
Output: [1,3,5,2,4]
Explanation: Nodes at positions 1, 3, and 5 come first, then 2 and 4.
linked listmedium
JavaScript
Loading...
Line 1, Char 1