Simple CPP solution with time complexity O(n) and space complexity O(1)


#1

ListNode* Solution::deleteDuplicates(ListNode* A) {
ListNodecur = A;
while(cur->next!=NULL)
{
if(cur->val==cur->next->val)
{
ListNode
t = cur->next->next;
free(cur->next);
cur->next = t;
}
else
cur = cur->next;
}
return A;
}