* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void reorderList(ListNode *head) {
if(head == nullptr){
return;
}
vector<ListNode*> record;
ListNode* cur = head;
while(cur != nullptr){
record.push_back(cur);
cur = cur->next;
}
int left=0, right=record.size()-1;
while(left < right){
record[left]->next = record[right];
left++;
if(left >= right){
break;
}
record[right]->next = record[left];
right--;
}
record[left]->next = nullptr;
}
};