标签:tco order bsp 连接 log lis https null color
143. Reorder List
https://www.cnblogs.com/grandyang/p/4254860.html
先将list的前半段和后半段分开,然后后半段进行逆序,然后再连接
class Solution { public: void reorderList(ListNode* head) { if(head == NULL) return; ListNode* p1 = head; ListNode* p2 = head; while(p2->next != NULL && p2->next->next != NULL){ p1 = p1->next; p2 = p2->next->next; } p2 = p1->next; p1->next = NULL; ListNode* pre = NULL; while(p2 != NULL){ ListNode* tmp = p2->next; p2->next = pre; pre = p2; p2 = tmp; } p1 = head; p2 = pre; while(p2 != NULL){ ListNode* tmp1 = p1->next; ListNode* tmp2 = p2->next; p1->next = p2; p2->next = tmp1; p1 = tmp1; p2 = tmp2; } return; } };
标签:tco order bsp 连接 log lis https null color
原文地址:https://www.cnblogs.com/ymjyqsx/p/10802768.html