LeetCode Algorithm 剑指 Offer 06. 从尾到头打印链表
生活随笔
收集整理的這篇文章主要介紹了
LeetCode Algorithm 剑指 Offer 06. 从尾到头打印链表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
劍指 Offer 06. 從尾到頭打印鏈表
Ideas
遍歷鏈表,每次在vector的頭部insert當前元素值。
Code
C++
class Solution { public:vector<int> reversePrint(ListNode* head) {vector<int> ans;while (head) {ans.insert(ans.begin(), head->val);head = head->next;}return ans;} };總結
以上是生活随笔為你收集整理的LeetCode Algorithm 剑指 Offer 06. 从尾到头打印链表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode Algorithm 面
- 下一篇: LeetCode Algorithm 剑