Delete duplicate-value nodes from a sorted linked list

  • + 0 comments

    JAVA

        public static SinglyLinkedListNode removeDuplicates(SinglyLinkedListNode llist) {
        // Write your code here
        SinglyLinkedListNode head = llist;
        SinglyLinkedListNode current = llist;
        SinglyLinkedListNode temp;
        
        
        if(llist == null){ 
            return llist;
        }
        
        while(current.next != null){
            
            if(current.data == current.next.data){
                temp = current.next.next;
                current.next.next = null;
                current.next = temp;
            }else{
                current=current.next;
            }
        }
        return head;
    
        }