Pregunta de entrevista de TechSophy

Implement scala code to remove duplicates

Respuesta de la entrevista

Anónimo

14 de may de 2020

def removeDuplicate(ls: List[Int]): List[Int] = { def fun(ls: List[Int], res: List[Int]): List[Int] = ls match { case Nil => res case x::xs => res.contains(x) match { case true => fun(xs, res) case false => fun(xs, res :+ x) } } fun(ls, List[Int]()) } NOTE: This will more optimised by using map.