Given an unsorted linked list, and without using a temporary buffer, write a method that will delete any duplicates from the linked list.
Моё решение на Scala:
def removeDuplicates[A](li: List[A]): List[A] = li match{ case Nil => li case h::Nil => li case h::t => if(t.contains(h)) removeDuplicates(t) else h::removeDuplicates(t) }
Комментариев нет:
Отправить комментарий