-
-
Save royki/e476b237fcc5f33d3e9c407414edfc4e 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