Nine Chapters Count Judge Net-original website http://www.jiuzhang.com/problem/74/
The topic gives a list of links, and then we want to flip the section m nodes in this list to the nth node part.
Online test of the subject http://www.lintcode.com/en/problem/reverse-linked-list-ii/
Answer
To better handle the header and the M nodes, the dummy node is introduced, because the head node may be flipped, and dummy node makes the head nodes flip the same as the normal node rollover operations. Since we are flipping the m-1 node to the nth node, and the next pointer of the first node changes, the next pointer to the N+1 node of the nth node changes, so we only consider m-1 to n+1 nodes. Then, you can flip the list I method, flip the first m to the nth node, and then the M-1 node's next pointer to the new M node, the nth node of the next pointer to the N+1 node to avoid broken list.
Reference Code
http://www.jiuzhang.com/solutions/reverse-linked-list-ii/
Nine-chapter algorithm surface question 73 Flip chain List II