首页 > 其他 > 详细

24 交换链表中相连的节点

时间:2018-12-25 12:09:18      阅读:172      评论:0      收藏:0      [点我收藏+]
    ListNode *swapPairs(ListNode *head) {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode *it = head;
        head = head->next;
        it->next = head->next;
        head->next = it;
        while (it->next != nullptr && it->next->next != nullptr) {
            ListNode *temp = it->next;
            it->next = it->next->next;
            temp->next = it->next->next;
            it->next->next = temp;
            it = it->next->next;
        }
        return head;
    }

24 交换链表中相连的节点

原文:https://www.cnblogs.com/INnoVationv2/p/10173091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!