Created
August 16, 2015 07:32
-
-
Save feliperazeek/84d0a03be5495c7213a8 to your computer and use it in GitHub Desktop.
Codility Missing Integer (https://codility.com/demo/results/demoKGH8FF-AP6/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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