Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save royki/e476b237fcc5f33d3e9c407414edfc4e to your computer and use it in GitHub Desktop.
Save royki/e476b237fcc5f33d3e9c407414edfc4e to your computer and use it in GitHub Desktop.
object Solution {
def solution(A: Array[Int]): Int = {
val (results, _) = A.sorted.foldLeft((0, 0)) { (t, item) =>
val (current, last) = t
val next = last + 1
item match {
case x if x < 0 => (current, last)
case `last` => (item, item)
case `next` => (item, item)
case _ => return next
}
}
results + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment