博客
关于我
剑指 Offer 06. 从尾到头打印链表 (简单)【栈】
阅读量:273 次
发布时间:2019-03-01

本文共 531 字,大约阅读时间需要 1 分钟。

题目:

在这里插入图片描述


代码:

/** * Definition for singly-linked list. * struct ListNode { *     int val; *     ListNode *next; *     ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {   public:    vector
reversePrint(ListNode* head) { stack
s; vector
ans; while(head!=NULL) { s.push(head->val); head=head->next; } while(s.size()) { ans.push_back(s.top()); s.pop(); } return ans; }};

转载地址:http://alao.baihongyu.com/

你可能感兴趣的文章