void reorderList(ListNode* head) { if(head==NULL||head->next==NULL) return; ListNode *l1=head,*l2=head->next; while(l2&&l2->next) { l1=l1->next; l2=l2->next->next; } ListNode *h=l1->next; l1->next=NULL; ListNode *p=h->next; h->next=NULL; while(p) { ListNode *s=p; p=p->next; s->next=h; h=s; } p=head; while(h) { ListNode *s=p->next; p->next=h; h=h->next; p->next->next=s; p=s; } }
[LeetCode] 143. Reorder List
最新推荐文章于 2020-07-19 12:52:19 发布