Simple C++ Recursive Solution


  • 0
    M
    class Solution {
    public:
        ListNode* removeElements(ListNode* head, int val) {
            if (!head) return 0;
            ListNode * tail = removeElements(head->next, val);
            if (head->val == val) return tail; else {
                head->next = tail;
                return head;
            }
        }
    };
    

Log in to reply
 

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