1/**2* Definition for singly-linked list.3* struct ListNode {4* int val;5* ListNode *next;6* ListNode() : val(0), next(nullptr) {}7* ListNode(int x) : val(x), next(nullptr) {}8* ListNode(int x, ListNode *next) : val(x), next(next) {}9* };10*/11class Solution {12public:13ListNode *reverseList(ListNode *head) {14if (head == NULL || head->next == NULL) {15return head;16}17ListNode *s = reverseList(head->next);18ListNode *t = head->next;19t->next = head;20head->next = NULL;21return s;22}23};