Skip to content

Instantly share code, notes, and snippets.

@adicuco
Created June 15, 2018 14:35
Show Gist options
  • Save adicuco/ab88660b3a6a2724ac74fdab0d037f12 to your computer and use it in GitHub Desktop.
Save adicuco/ab88660b3a6a2724ac74fdab0d037f12 to your computer and use it in GitHub Desktop.
solution for Odd Occurrences in Array Task on Codility
function solution(A) {
var B = [];
var max = 0;
for (var i = 0; i < A.length; i++) {
if (typeof B[A[i]] === "undefined") {
B[A[i]] = 0;
if (A[i] > max) max = A[i];
}
B[A[i]]++;
}
for (var j = 1; j <= max; j++) {
if (typeof B[j] != "undefined") if (B[j] % 2 != 0) return j;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment