C++ vector solution


#1

ListNode* Solution::solve(ListNode* A) {
int i ,len=0;
vectorv;
ListNode *head=A;
while(head!=NULL){
v.push_back(head->val);
len++;
head=head->next;
}
if(len%2==0){
for(i=1;i<(len/2+1);i=i+2){
swap(v[i],v[len-i]);
}
}
else {
for(i=1;i<(len/2+1);i=i+2){
swap(v[i],v[len-1-i]) ;
}
}
head=A;
int j=0;
while(head!=NULL){
head->val=v[j];
head=head->next;
j++;
}
return A;
}