Skip to content

Instantly share code, notes, and snippets.

@sontl
Created April 5, 2015 02:19
Show Gist options
  • Save sontl/0919ee9ec667c8cf2fee to your computer and use it in GitHub Desktop.
Save sontl/0919ee9ec667c8cf2fee to your computer and use it in GitHub Desktop.
Codility - MissingInteger
// you can use console.log for debugging purposes, i.e.
// console.log('this is a debug message');
// you can use console.log for debugging purposes, i.e.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 0.12)
var counting = [];
for ( var i = 0; i < A.length; i++) {
if(counting[A[i]]){
counting[A[i]] ++;
} else {
counting[A[i]] = 1;
}
}
for (var i=1; i < counting.length; i++) {
if (!counting[i]) {
return i;
}
}
return (counting.length > 0) ? counting.length : 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment