Nine-chapter algorithm surface question 73 Flip chain List II

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.