[LeetCode] 143. Reorder List

来源:互联网 发布:听收音机的软件 编辑:程序博客网 时间:2024/06/05 03:21
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;}}
原创粉丝点击