从尾到头打印链表
题目描述
输入一个链表,从尾到头打印链表每个节点的值。
思路:直接打印就好了
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class
Solution {
vector<
int
> value;
public
:
vector<
int
> printListFromTailToHead(struct ListNode* head) {
ListNode *p;
p = head;
if
(p){
printListFromTailToHead(p->next);
value.push_back(p->val);
}
return
value;
}
};