Given the head of a linked list and positions m and n, reverse the nodes from position m to n and return the head. Example: Input: head = [1,2,3,4,5], m = 2, n = 4 Output: [1,4,3,2,5] Explanation: Nodes from 2 to 4 are reversed. Pattern focus: In-Place Reversal (reverse sublist).
head = ListNode, m = int, n = int
return ListNode
Example 1:
Input:
head = [1,2,3,4,5] m = 2 n = 4
Output:
[1,4,3,2,5]
Explanation:
Sublist [2,3,4] is reversed to [4,3,2].