ListNode* reverseList(ListNode* head) {
stack<int> s;
ListNode* t=head;
while(t!=NULL)
{
s.push(t->val);
t=t->next;
}
t=head;
while(t!=NULL)
{
t->val = s.top();
s.pop();
t=t->next;
}
return head;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter