Delete duplicate-value nodes from a sorted linked list

  • + 0 comments

    Java Script

    function removeDuplicates(llist) {
        // Write your code here
        let curData = llist.data;
        let list = new SinglyLinkedList();
        list.insertNode(curData);
        while (llist) {
            llist = llist.next;
            const nextData = llist?.data;
            if (nextData && curData !== nextData) {
                list.insertNode(nextData);
                curData = nextData;
            }
        }
        return list.head;
    }