输入一个链表,从尾到头打印链表每个节点的值。
/**
*
struct ListNode {
*
int val;
*
struct ListNode *next;
*
ListNode(int x) :
*
val(x), next(NULL) {
*
}
*
};
*/
class
Solution {
public
:
vector<
int
>
printListFromTailToHead(struct ListNode* head) {
vector<
int
>
value;
if
(head!=NULL)
{
value.insert(value.begin(),head->val);
while
(head->next!=NULL)
{
value.insert(value.begin(),head->next->val);
head=head->next;
}
}
return
value;
}
};