//利用栈来实现
/**
* 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 节
全部评论
相关推荐
06-25 19:12
广西民族大学相思湖学院 Java 点赞 评论 收藏
分享
07-01 16:05
河南师范大学 Java 点赞 评论 收藏
分享