Delete duplicate-value nodes from a sorted linked list

Sort by

recency

|

904 Discussions

|

  • + 0 comments

    My solution in C#: easiest solution

    static SinglyLinkedListNode removeDuplicates(SinglyLinkedListNode llist) { SinglyLinkedListNode currNode = llist;

        while(currNode !=null && currNode.next!= null)
        {
            if(currNode.data==currNode.next.data)
            {
                currNode.next = currNode.next.next;
            }
            else 
            currNode = currNode.next;
    
        }
        return llist;
    }
    
  • + 0 comments
    let node = llist
    
    while(node != null) {
        if(node.next== null) {
            return llist
        }
    
        let firstNode = node.data
        let secondNode = node.next.data   
    
        if(firstNode != secondNode) {
            node = node.next
        }         
    
        if(firstNode == secondNode) {
            node.next = node.next.next
        }
    }
    

    return llist

  • + 0 comments

    Hi There i am try to make a search box just link cardiology cpt code cheat sheet any one who can make me code like this .... thanks

  • + 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;
    
        }
    
  • + 0 comments

    Python 3

    def removeDuplicates(llist):
        # Write your code here
        head=llist
        while llist:
            nxt=llist.next
            if nxt and llist.data==nxt.data:
                llist.next=nxt.next
            else:
                llist=llist.next
        return head