3 lines easy iterative solution in C++


  • 0
    I
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode *temp = head;
        while (head != NULL) {
            while (head->next != NULL && head->next->val == head->val) head->next = head->next->next;
            head = head->next;
        }
        return temp;
    }
    

Log in to reply
 

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