Difficult:Medium
題目
Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.
翻譯
給定單鍊錶的頭部和左右兩個整數,其中left <= right,將列表的節點從左到右反轉,並返回反轉後的列表。
範例
Example 1:
1 | Input: head = [1,2,3,4,5], left = 2, right = 4 |
Example 2:
1 | Input: head = [5], left = 1, right = 1 |
解題思路
1.反轉N個元素
Solution
1 | var reverseBetween = function(head, left, right) { |