Created
August 16, 2015 04:41
-
-
Save feliperazeek/fb7252b5ff8c0bbc1b3b 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