Created
December 1, 2015 06:28
-
-
Save divmgl/5494e2ea914d6edd4afe to your computer and use it in GitHub Desktop.
MissingInteger Javascript solution 100%/100%
This file contains hidden or 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
function solution(A) { | |
var F = []; // Found list | |
var I = 0, V = 0; // Counter, container | |
while (I < A.length) { // Iterate through the array | |
V = A[I]; // Store the value | |
I++; // Increase counter | |
if (F[V]) continue; // If the value exists, continue | |
F[V] = true; // Store the value | |
} | |
I = 0; | |
do { // Look for the first value that doesn't appear | |
I++; | |
} while (F[I]) // We do this by looping through the array until falsy | |
return I; // Return the number of times we iterated | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment