Why is this code to reverse a linked list not working? I want to know exactly what I am doing wrong.
struct ListNode* reverseList(struct ListNode* head) {
if(head==NULL || head->next==NULL) return head;
struct ListNode* p=reverseList(head->next);
p->next=head;
return head;
}
When I dry run, it seems to work fine but then gives TLE.
New contributor
Udita Gupta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.