Created
January 29, 2018 07:32
-
-
Save clarkdo/4c07619a0b46894317569149e7573c2b to your computer and use it in GitHub Desktop.
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
class Solution { | |
public int solution(int X, int[] A) { | |
int second = -1; | |
int count = 0; | |
boolean[] counter = new boolean[X]; | |
for (int i = 0; i < A.length; i++) { | |
int pos = A[i]; | |
if (pos <= A.length && !counter[pos-1]) { | |
counter[pos-1] = true; | |
count++; | |
} | |
if (count == X) { | |
second = i; | |
break; | |
} | |
} | |
return second; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment