My 6 line C++ recursive solution


  • 0
    C
    ListNode* removeElements(ListNode* head, int val) {
            if(!head) return NULL;
            if(head->val == val)
                return removeElements(head->next,val);
            else{
                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.