Created
June 15, 2018 16:51
-
-
Save adicuco/27b38551dfc8f58f372528137a2eca19 to your computer and use it in GitHub Desktop.
100% solution for Permutation Missing Element on Codility
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
function solution(A) { | |
if (A.length == 0) return 1; | |
var min = 100000; | |
var max = 0; | |
var B = []; | |
for (var i = 0; i < A.length; i++) { | |
B[A[i]] = 0; | |
if (A[i] > max) max = A[i]; | |
if (A[i] < min) min = A[i]; | |
} | |
if (min != 1) return 1; | |
if (max == A.length) return max + 1; | |
for (; min <= max; min++) { | |
if (typeof B[min] === "undefined") return min; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment