Short and clean solution in c++


  • 0
    S
    class Solution {
    public:
        ListNode* deleteDuplicates(ListNode* head) {
            ListNode* head1 = head , * head2 = head;
            while(head1){
            while(head2-> next != NULL && head2->val == head2->next->val) head2= head2->next;
            head2= head2->next;
            head1->next= head2;
            head1= head1->next;
            }
            return head;
        }
    };

Log in to reply
 

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