Reverse Linked List II
Aug 4, 2016
https://leetcode.com/problems/reverse-linked-list-ii/
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
Solution:
This problem is a “harder” versio of the 206. Reverse Linked List
I followed the idea of 206. Reverse Linked List by first find thehead
of the linked list that we need to reverse, then the tail
, which is null
for the previous qustion. Then start with head
,
reverse the linkedlist until we reach the tail
node:
|
|