提交时间:2015-09-25 语言:C++ 运行时间:0ms 占用内存:8552K 状态:答案正确
/*
遍历一次链表,每遍历到一个结点,就将结点的值插入到vecotr的开始。
*/
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(struct ListNode* head) {
struct ListNode *p = head;
vector<int> rt;
while(p != NULL){
rt.insert(rt.begin(),p->val);
p = p->next;
}
return rt;
}
};
原文:http://www.cnblogs.com/qianmacao/p/4839533.html