-
-
Save royki/ce9234259b7f455e2b0850a0d963d8db to your computer and use it in GitHub Desktop.
Codility - PermCheck (https://codility.com/demo/results/demoC7B3DN-3UN/)
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
import java.util.BitSet | |
object Solution { | |
def solution(A: Array[Int]): Int = { | |
val bitz = new BitSet(A.size + 1) | |
val good = A.foldLeft(true)((current, i) => | |
if (current) { | |
(i, bitz.get(i)) match { | |
case (x, _) if x > A.size => | |
false | |
case (x, _) if x < 1 || x > 1000000000 => | |
false | |
case (0, _) => | |
false | |
case (_, true) => | |
false | |
case _ => | |
bitz.set(i) | |
true | |
} | |
} else false | |
) | |
if (good && A.size > 0 && A.size <= 100000) 1 | |
else 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment