Compare commits

...

2 Commits

Author SHA1 Message Date
67baf83d27 Merge branch 'main' of http://git.wxchen.site/wxchen/lc 2024-07-08 23:35:20 +08:00
f5bc575378 home 2024-07-08 23:34:14 +08:00

View File

@@ -3,11 +3,45 @@
* @Version: 1.0 * @Version: 1.0
* @Autor: wxchen * @Autor: wxchen
* @Date: 2022-11-21 15:27:10 * @Date: 2022-11-21 15:27:10
* @LastEditTime: 2022-11-21 21:08:42 * @LastEditTime: 2024-07-03 23:15:58
*/ */
#include <iostream> #include <iostream>
#include <vector>
int main() { using namespace std;
std::cout << "hello" << std::endl;
return 0; struct ListNode {
int val;
ListNode* next;
// ListNode(int x) : val(x), next(NULL) {} //
ListNode(int x, ListNode* n = NULL) : val(x), next(n) {}
};
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
reverse(head);
return (result);
}
private:
vector<int> result;
void reverse(ListNode* head) {
if (head != nullptr) {
if (head->next != nullptr) {
reversePrint(head->next);
}
result.push_back(head->val);
}
};
};
int main(int, char**) {
ListNode* head = new ListNode(1);
head -> next = new ListNode(3);
head -> next -> next = new ListNode(2);
Solution s;
std::cout << s.reversePrint(head)[0] << s.reversePrint(head)[1] << s.reversePrint(head)[2] << std::endl;
} }