Created
January 10, 2020 14:14
-
-
Save ShinJJang/924f5815dc3cd5b8b01797de79c741ed 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) { | |
// write your code in Java SE 8 | |
boolean[] checkArray = new boolean[X]; | |
for(int i=0; i<A.length; i++) { | |
boolean is_leave = checkArray[A[i] - 1]; | |
if (is_leave == false) { | |
checkArray[A[i]- 1] = true; | |
X -= 1; | |
if (X == 0) { | |
return i; | |
} | |
} | |
} | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment