美文网首页Lintcode程序员
Lintcode36 Reverse Linked List I

Lintcode36 Reverse Linked List I

作者: 代码码着玩 | 来源:发表于2017-04-04 14:03 被阅读26次

    【题目描述】

    Reverse a linked list from position m to n.

    Notice:Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list.

    翻转链表中第m个节点到第n个节点的部分

    注意:m,n满足1 ≤ m ≤ n ≤ 链表长度

    【题目链接】

    http://www.lintcode.com/en/problem/reverse-linked-list-ii/

    【题目解析】

    反转整个链表的变种,指定了起点和终点。由于m=1时会变动头节点,所以加入一个dummy头节点

    1. 找到原链表中第m-1个节点start:反转后的部分将接回改节点后。

    2. 将从p = start->next开始,长度为L = n-m+1的部分链表反转。

    3. 最后接回

    【参考答案】

    http://www.jiuzhang.com/solutions/reverse-linked-list-ii/

    相关文章

      网友评论

        本文标题:Lintcode36 Reverse Linked List I

        本文链接:https://www.haomeiwen.com/subject/xwjvnttx.html