题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
反转链表:用一个栈
stack<int> s;
ListNode * p = pHead;
while(p != nullptr)
{
s.push(p->val);
p = p->next;
}
ListNode * q = pHead;
while(q != nullptr)
{
q->val = s.top();
s.pop();
q = q->next;
}
return pHead;
}
```</int>