Created
April 5, 2015 02:19
-
-
Save sontl/0919ee9ec667c8cf2fee to your computer and use it in GitHub Desktop.
Codility - MissingInteger
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
// 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