Two Pointer with O(1) Space complexity


#1
ListNode* Solution::deleteDuplicates(ListNode* A) {
if(A==NULL) return A;
ListNode* first = A;
ListNode* second = A;
while(true){
    while(second!=NULL and first->val==second->val){
        second = second->next;
    }
    first->next = second;
    first = second;
    if(second==NULL) break;
    second = second->next;
}
return A;}