Reorder List Posted on 2018-10-05 Descriptionhttps://leetcode.com/problems/reorder-list/description/ Solution12345678910111213141516171819202122232425262728293031323334353637383940414243/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* reverse(ListNode* head) { if (!head || !head->next) return head; ListNode* ret = reverse(head->next); head->next->next = head; head->next = NULL; return ret; } void reorderList(ListNode* head) { if (!head || !head->next) return; ListNode* slow = head; ListNode* quick = head; while(quick && quick->next && quick->next->next) { slow = slow->next; quick = quick->next->next; } ListNode* newHead = reverse(slow->next); slow->next = NULL; //Merge crossly from head and newHead; ListNode* cur = head; ListNode* another = newHead; while (cur && another) { ListNode* temp = cur; cur = cur->next; temp->next = another; temp = another; another = another->next; temp->next = cur; } }};