LeetCode 92 - Reverse Linked List II
Difficulty: medium
Problem Description
English (Reverse Linked List II)
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.
Example 1:
graph LR
node11((1))
node12((2))
node13((3))
node14((4))
node15((5))
node11 ---> node12 ---> node13 ---> node14 ---> node15
node21((1))
node22((4))
node23((3))
node24((2))
node25((5))
node21 ---> node22 ---> node23 ---> node24 ---> node25
1 |
|
Example 2:
1 |
|
Constraints:
- The number of nodes in the list is
n
. 1 <= n <= 500
-500 <= Node.val <= 500
1 <= left <= right <= n
Follow up: Could you do it in one pass?
Chinese (环形链表 II)
给你单链表的头指针 head
和两个整数 left
和 right
,其中 left <= right
。请你反转从位置 left
到位置 right
的链表节点,返回 反转后的链表 。
示例 1:
graph LR
node11((1))
node12((2))
node13((3))
node14((4))
node15((5))
node11 ---> node12 ---> node13 ---> node14 ---> node15
node21((1))
node22((4))
node23((3))
node24((2))
node25((5))
node21 ---> node22 ---> node23 ---> node24 ---> node25
1 |
|
示例 2:
1 |
|
提示:
- 链表中节点数目为
n
1 <= n <= 500
-500 <= Node.val <= 500
1 <= left <= right <= n
进阶: 你可以使用一趟扫描完成反转吗?
Solution
1 |
|
LeetCode 92 - Reverse Linked List II
http://wasprime.github.io/Algorithm/LeetCode/LinkedList/LeetCode-92-Reverse-Linked-List-II/