Recursive solution , takes 1 ms. Links to better understand call stack


  • 0

    public ListNode deleteDuplicates(ListNode head) {

    ListNode temp=head;
    

    if(temp==null) return null;
    if(temp.next==null) return temp;
    if(temp.val==temp.next.val)
    temp.next=temp.next.next;

    }else{
    temp=temp.next;
    }
    deleteDuplicates(temp);
    return head;
    }


Log in to reply
 

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