Skip to content

Instantly share code, notes, and snippets.

@feliperazeek
Created August 14, 2015 06:01
Show Gist options
  • Save feliperazeek/2ee51451a19c7efb539f to your computer and use it in GitHub Desktop.
Save feliperazeek/2ee51451a19c7efb539f to your computer and use it in GitHub Desktop.
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