//利用栈来实现
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> res;
while(head)
{
res.push_back(head->val);
head = head->next;
}
return vector<int>(res.rbegin(),res.rend());
}
};
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> res;
while(head)
{
res.push_back(head->val);
head = head->next;
}
return vector<int>(res.rbegin(),res.rend());
}
};
2020-04-30
在牛客打卡8天,今天学习:刷题 2 道/代码提交 2 次/学习课程 1 节
全部评论
相关推荐
点赞 评论 收藏
分享
2025-12-26 10:52
河北传媒学院 Java 点赞 评论 收藏
分享
三奇智元机器人科技有限公司公司福利 86人发布