Clear C++ recursive solution


  • 0
    K
    class Solution {
    public:
        ListNode* deleteDuplicates(ListNode* head) {
            if(!head || !head->next) return head;
            if(head->val == head->next->val) {
                head->next = head->next->next;
                deleteDuplicates(head);
            }
            else head->next = deleteDuplicates(head->next);
            
            return head;
        }
    };
    

Log in to reply
 

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