剑指offer:从尾到头打印链表
程序员文章站
2022-05-06 10:08:45
...
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> value;
value.clear();
if(head)
{
value.insert(value.begin(), head -> val);
while(head -> next)
{
value.insert(value.begin(), head -> next -> val);
head = head -> next;
}
}
return value;
}
};
下一篇: 弧形进度条(动画版)