代码:
class Solution {
public:
vector reversePrint(ListNode* head) {
ListNode* node = head;
int count = 0;
while( node != NULL) {
count++;
node = node->next;
}
vector ans(count);
node = head;
for (int i = count -1 ; i >= 0; i --) {
ans[i] = node->val;
node = node->next;
}
return ans;
}
};
时间复杂度:O(n)。
空间复杂度:O(n)。



