Skip to content

Instantly share code, notes, and snippets.

@royki
Forked from feliperazeek/CodilityDistinct.scala
Created July 31, 2019 20:58
Show Gist options
  • Save royki/b45ab5ec03e2585d7e26a46f51170c96 to your computer and use it in GitHub Desktop.
Save royki/b45ab5ec03e2585d7e26a46f51170c96 to your computer and use it in GitHub Desktop.
object Solution {
def solution(A: Array[Int]): Int = {
val positive = new java.util.BitSet()
val negative = new java.util.BitSet()
A.foldLeft(0) { (current, i) =>
val duplicate = if (i < 0) (negative get i * -1)
else (positive get i)
duplicate match {
case true =>
current
case false =>
if (i >= 0) positive set i
else negative set i * -1
current + 1
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment