Why is it showing wrong answer


#1

ListNode* Solution::solve(ListNode* A) {
if(A==nullptr || (A->next)==nullptr) return A;
ListNode *h= A;
h= h->next;
stacks;
while(h && (h->next)){
s.push(h->val);
h= h->next->next;
}
h= A;
h= h->next;
while(h && (h->next)){
h->val = s.top();
s.pop();
h= h->next->next;
}
return A;
}

Your submission failed for the following input:

A : [ 1 -> 2 -> 3 -> 4 ]

Your function returned the following :

1 -> 2 -> 3 -> 4

The expected returned value :

1 -> 4 -> 3 -> 2