Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final def drop(n: Int): LinkedList[A] = {
- val len = (this.length - n)
- @tailrec def inner(remaining: LinkedList[A]): LinkedList[A] =
- remaining match {
- case Nil() => Nil()
- case Cons(h, t) => if (t.length > len) inner(t) else t
- }
- if (n > this.length) Nil()
- else inner(this)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement