내 답안
import java.util.ArrayList;
class Solution {
public int[] solution(int[] arr, int k) {
ArrayList<Integer> intList = new ArrayList<Integer>();
for(int i = 0; i < arr.length; i++) {
if(intList.size() == k) break;
if(!intList.contains(arr[i])) intList.add(arr[i]);
}
while(intList.size() < k)
intList.add(-1);
return intList.stream().mapToInt(x->x).toArray();
}
}
Java
복사
다른사람 풀이
import java.util.Arrays;
import java.util.stream.IntStream;
class Solution {
public int[] solution(int[] arr, int k) {
return IntStream.concat(Arrays.stream(arr).distinct(), IntStream.range(0, k).map(i -> -1)).limit(k).toArray();
}
}
Java
복사