当前位置:网站首页>剑指 Offer 06. 从尾到头打印链表
剑指 Offer 06. 从尾到头打印链表
2022-06-25 15:32:00 【anieoo】

solution:
遍历一边链表,用数组保存节点值,最后reverse. 时间复杂度O(n)
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
vector<int> res;
ListNode *cur = head;
while(cur != NULL) {
res.push_back(cur->val);
cur = cur->next;
}
reverse(res.begin(),res.end());
return res;
}
};
边栏推荐
- Learning notes on February 5, 2022 (C language)
- The last glory of the late Ming Dynasty - the battle of Korea
- 网上办理股票开户安全吗?
- The robot is playing an old DOS based game
- Go closure usage example
- Distributed token
- [paper notes] semi supervised object detection (ssod)
- Software packaging and deployment
- Getting started with lambda8 new features
- AB string interchange
猜你喜欢

QT source code online view

Stack and queue

QT excel table read / write library - qtxlsx

Kali modify IP address

Learning notes on February 8, 2022 (C language)

User defined data type - structure

Generic - learning notes

Globally unique key generation strategy - implementation principle of the sender

Fishing detection software

Learning notes on February 5, 2022 (C language)
随机推荐
Daily question, magic square simulation
QT source code online view
Is it safe to open a stock account online?
Getting started with lambda8 new features
Leetcode123 timing of buying and selling stocks III
Why do I need message idempotence?
CV pre training model set
Detailed description of crontab command format and summary of common writing methods
2. operator and expression multiple choice questions
Learning notes on February 8, 2022 (C language)
p1408
basic_ String mind map
Fishing detection software
Shared memory synchronous encapsulation
[paper notes] semi supervised object detection (ssod)
[paper notes] rethinking and improving relative position encoding for vision transformer
Common dynamic memory errors
The robot is playing an old DOS based game
Learning notes on February 18, 2022 (C language)
google_ Breakpad crash detection