Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void reorderList(ListNode* head) {
- if(!head||!head->next)return;
- ListNode*h1=head,*h2=head->next;
- while(h2&&h2->next)
- {
- h1=h1->next;
- h2=h2->next->next;
- }
- h2=h1->next;
- h1->next=NULL;
- h1=head;
- ListNode*pre=NULL;
- while(h2)
- {
- ListNode*cur=h2->next;
- h2->next=pre;
- pre=h2;
- h2=cur;
- }
- h2=pre;
- while(h2)
- {
- pre=h1->next;
- h1=h1->next=h2;
- h2=pre;
- }
- }
Add Comment
Please, Sign In to add comment