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
*/
11
class Solution {
12
public:
13
ListNode *reverseList(ListNode *head) {
14
if (head == NULL || head->next == NULL) {
15
return head;
16
}
17
ListNode *s = reverseList(head->next);
18
ListNode *t = head->next;
19
t->next = head;
20
head->next = NULL;
21
return s;
22
}
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0