14ms C++ code, looking for suggestions


  • 0
    I
    ListNode *deleteDuplicates(ListNode *head) {
            if(!head)
    		return head;
    	ListNode *assist = new ListNode(0), *pre = assist, *cur = assist, *next = head;
    	assist -> next = head;
    	do
    	{
    		cur = cur -> next;
    		if(next)
    			next = next -> next;
    		if(!cur || !next || cur -> val != next -> val)
    		{
    			pre -> next = cur;
    			pre = cur;
    		}
    		else
    			while(next && cur -> val == next -> val)
    			{
    				cur = cur -> next;
    				next = next -> next;
    			}
    	}
    	while(cur);
    	return assist -> next;
    }

Log in to reply
 

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