Question Type: Medium ποΈ
Complexities: Time: O(n), Space: O(n) π©
Code: π
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;
}
};
Top comments (0)