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;
}
};
LeetCode剑指 Offer 06. 从尾到头打印链表
最新推荐文章于 2023-08-25 09:44:36 发布