Why this can not pass the test


  • -1
    L

    int n_index = 0;

    struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
    if(head == NULL){
    n_index ++;
    return head;
    }
    if(n_index == 0)
    {
    head->next = removeNthFromEnd(head->next,n);
    }
    if(n == n_index)
    {

        n_index++;
        struct ListNode* temp = head;
        head = head->next;
        free(temp);
        return head;
    }
    else
    {
        
        n_index ++;
        return head;
    }
    

    }

    test case is [1,2] n=2, when i use test case ,this result is right. but when i submit solution,[1,2] is output [1,2]


Log in to reply
 

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