Delete duplicate-value nodes from a sorted linked list

  • + 0 comments

    In Kotlin:

    fun removeDuplicates(llist: SinglyLinkedListNode?): SinglyLinkedListNode? {
        var current = llist;
        
        while (current != null && current.next != null) {
            if (current.data == current?.next?.data) {
                current.next = current?.next?.next;
            } else {
                current = current?.next
            }
        }
        
        return llist
    }
    

    But I does not work in some tests. I think it is the compiler bug.