Description
Reverse a linked list from position m to n. Do it in one-pass.
Note: 1 ≤ m ≤ n ≤ length of list.
Example:
1 | Input: 1->2->3->4->5->NULL, m = 2, n = 4 |
解法
基本的链表操作题,为解决对于链表头的处理,常在表头插入空项,即dummy指针。对于翻转链表,采用在链表头部插入的技术即可。
具体代码如下:
1 | class Solution { |