68. Reorder by Ends
Medium
Return the nodes of the list in this order: first, last, second, second-to-last, and so on. If the number of nodes is odd, the middle node should be left at the end. The order of values in the original list should not change except for this rearrangement.
Example 1
Input: head = [1, 2, 3, 4, 5]
Output: [1, 5, 2, 4, 3]
Example 2
Input: head = [2, 6, 8, 10]
Output: [2, 10, 6, 8]
Constraints
- 1 <= tamanho da lista <= 10000.
Linked listTwo pointers
Saved in this browser
Caso 1
head =
[1,2,3,4,5]
Expected =
[1,5,2,4,3]
Caso 2
head =
[2,6,8,10]
Expected =
[2,10,6,8]
Run checks these 2 cases. Submit runs all 6, including hidden ones.