class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode *new_head = nullptr;
ListNode *cur = head;
while (cur) {
ListNode *iter = cur->next;
cur->next = new_head;
new_head = cur;
cur = iter;
}
return new_head;
}
};
class Solution {
public:
ListNode* reverseList(ListNode* head) {
if (!head || !head->next) {
return head;
}
ListNode* newHead = reverseList(head->next);
head->next->next = head;
head->next = nullptr;
return newHead;
}
};