重排链表
将链表改为1,n-1,2,n-2,3…的顺序
class Solution {
public:
void reorderList(ListNode* head) {
if(!head)
return ;
vector<ListNode*> v;
ListNode* p=head;
while(p){
v.push_back(p);
p=p->next;
}
int l=0;
int r=v.size()-1;
while(l<r){
v[l]->next=v[r];
v[r]->next=v[l+1];
r--;
l++;
}
v[l]->next=nullptr;
}
};