Simple C++ solution (#INCLUDE COMMENTS)


#1

#define node ListNode
ListNode* Solution::deleteDuplicates(ListNode* head)
{
node *curr=head,*nxt=head->next;
while(nxt!=NULL)
{
if(curr->val==nxt->val)
{
nxt=nxt->next;
curr->next=nxt;
}
else
{
curr=curr->next;
nxt=nxt->next;
}
}
return head;
}

Sorry for indentation, mine is correct but the displayed one isn’t.