Elegant 3 Line Solution (C++)

  • 1

    Why do it iteratively when it can be written in 3 lines...

    ListNode* removeElements(ListNode* head, int val) {
        if (!head) return head;
        head->next = removeElements(head->next, val);
        return (head->val == val)? head->next : head;

Log in to reply

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