class Solution {
public:
vector<int> reversePrint(ListNode* head) {
vector<int> ans;
while (head != NULL) {
ans.push_back(head->val);
head = head->next;
}
reverse(ans.begin(),ans.end());
return ans;
}
};
剑指 Offer 06. 从尾到头打印链表
最新推荐文章于 2024-09-14 22:25:23 发布