Delete duplicate-value nodes from a sorted linked list

  • + 0 comments

    Hello I tried to solve this with kotlin cause Im Software android Engineer and I feel more familiar with kotlin

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

    My logic is correct but Hacker rank has a kind of bug working with nulleables types the same logic in python works correctly why?

    def removeDuplicates(llist):
     current = llist
    
    while current.next is not None:
    if current.data == current.next.data:
    current.next = current.next.next
    else:
    current = current.next
    
    return llist