Delete duplicate-value nodes from a sorted linked list

  • + 1 comment

    my Java Sol :

    Node RemoveDuplicates(Node head) {
        Node h=head,pre=head;
       while(head.next!=null){
           if(pre.data!=head.data){pre=head;}
           head=head.next;
           if(pre.data==head.data){pre.next=head.next;}      
       }
        return h;
    }