Delete duplicate-value nodes from a sorted linked list

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