Skip to content

Instantly share code, notes, and snippets.

@divmgl
Created December 1, 2015 06:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divmgl/5494e2ea914d6edd4afe to your computer and use it in GitHub Desktop.
Save divmgl/5494e2ea914d6edd4afe to your computer and use it in GitHub Desktop.
MissingInteger Javascript solution 100%/100%
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