Remove Duplicates from the List recursively
问题 I want to remove duplicates from the list recursively using pattern matching with Scala here is my input val xs = List(1,2,3,4,6,3,2,7,9,4) Tried code: def removeDuplicates(xs : List[Int]) : List[Int] = xs match { case Nil =>Nil case x::ys => { if(ys.contains(x)){ removeDuplicates(ys) } else { } /// ??? } } I was stuck at the question mark, how to appened my result to the mutable list and return it. Thank you. 回答1: You're close: def removeDuplicates(xs : List[Int]) : List[Int] = xs match {