Delete duplicate-value nodes from a sorted linked list

  • + 1 comment

    My Java solution too.

    Node RemoveDuplicates(Node head) {
        Node n= head;
        while(head.next!=null)
            {
           
            if( head.data==head.next.data)
                head.next=head.next.next;
            else
                head=head.next;
        }
        return n;
    }