We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defremoveDuplicates(llist:SinglyLinkedListNode):SinglyLinkedListNode={// Write your code hereif(llist==null||llist.next==null){llist}elseif(llist!=null&&llist.next!=null&&llist.next.next==null){if(llist.data!=llist.next.data){llist}else{llist.next=nullllist}}else{varprevious:SinglyLinkedListNode=llistvarcurrent:SinglyLinkedListNode=previous.nextvarnext:SinglyLinkedListNode=current.nextvarmySet=scala.collection.immutable.Set[Int](previous.data)while(current!=null){if(mySet.contains(current.data)){previous.next=nextcurrent.next=nullcurrent=nextnext=if(current==null)nullelsecurrent.next}else{mySet=mySet.+(current.data)previous=previous.nextcurrent=previous.nextnext=if(current==null)nullelsecurrent.next}}llist}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Delete duplicate-value nodes from a sorted linked list
You are viewing a single comment's thread. Return to all comments →
Scala