What is the problem in my following code?It is showing "Last executed input:[]".


  • 0
    M
    struct ListNode* reverseList(struct ListNode* head){
        if(head->next!=NULL){
                reverseList(head->next)->next=head;
                return head;
            }
        else
            return head;
    }
    

    Please help me solve this problem.


  • 1
    K

    the input has head as null. so when you try and get head->next it can't since null has no next value.

    to fix you would need to check if head is null or if head->next is null not just head->next


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.