/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head)
{
vector<int >result ;
stack<int>st;
if(head==nullptr)
return result;
ListNode *p=head;
while(p)
{
st.push(p->val);
p=p->next;
}
while(st.size())
{
int temp=st.top();
result.push_back(temp);
st.pop();
}
return result;
}
};
第三 题 剑指offer 链表的逆序打印
最新推荐文章于 2022-04-01 07:15:00 发布