C++ 4 lines recursive solution


  • 8
    J
    ListNode* removeElements(ListNode* head, int val) {
        if (head == NULL) return NULL;
        if (val == head->val) return removeElements(head->next,val);
        head->next = removeElements(head->next,val);
        return head;
    }

Log in to reply
 

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