You are given the head of a linked list and two positions left and right, with left <= right. Positions start at 1. Reverse the nodes that sit between position left and position right (both included), then return the list.
How the judge passes the data
Examples
Example 1:
Input: head = [10,20,30,40,50,60], left = 3, right = 5
Output: [10,20,50,40,30,60]
Explanation: The part [30,40,50] is reversed to [50,40,30].
Example 2:
Input: head = [1,2], left = 1, right = 2
Output: [2,1]
Explanation: The whole list is reversed.
Example 3:
Input: head = [8], left = 1, right = 1
Output: [8]
Explanation: Reversing a single node changes nothing.