-
-
Save royki/b45ab5ec03e2585d7e26a46f51170c96 to your computer and use it in GitHub Desktop.
Codility Distinct (https://codility.com/demo/results/demoHBXM7Z-JDA/)
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 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