Skip to content

Instantly share code, notes, and snippets.

@feliperazeek
Created August 16, 2015 07:32
Show Gist options
  • Save feliperazeek/84d0a03be5495c7213a8 to your computer and use it in GitHub Desktop.
Save feliperazeek/84d0a03be5495c7213a8 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