leetcode_92
Reverse a linked list from position m to n. Do it in one-pass.
Note:
1 ≤ m ≤ n ≤ length of list.
Solutions
Iteration. reverse link one by one
This is a simplified reverse-nodes-in-k-group problem(25). ie: reverse-nodes-in-k-group one time.
Just copy paste the reverse-k nodes code
Iterration. insertion
Borrowed from others.
Set the former node of the m'th(1 based) node as the
head
node or docking point.Set the m'th node as
cur
node.In each step, insert the
cur node's next node
after thehead
node. The head node and cur node are not changed during the whole process.After inserted
n - m
times, reversion done.In this pespective, it's easy to rewrite
reverse-list-in-k-group
quickly and concisely with the same idea.
Recursion
Last updated
Was this helpful?