import java.util.Arrays;
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public static void main(String[] args) {
int [] A = {2, 3, 1, 5};
solution(A);
}
public static int solution(int[] A) {
// write your code in Java SE 8
int answer = 0;
int [] arr = A.clone();
Arrays.sort(arr);
for(int i = 0; i < arr.length; i++){
if(arr[i] != i+1){
answer = i+1;
break;
}
}
return answer;
}
}
수...수정
import java.util.Arrays;
class Solution {
public static void main(String[] args) {
//int [] A = {2, 3, 1, 5};
int [] A = {};
solution(A);
}
public static int solution(int[] A) {
// write your code in Java SE 8
int answer = 1;
int [] arr = A.clone();
Arrays.sort(arr);
for(int i = 0; i < arr.length; i++){
if(arr[i] != i+1){
answer = i+1;
return answer;
}
}
return A.length + 1; //마지막 숫자가 빠지는 경우 체크
}
}
댓글
댓글 쓰기