public int solution1(int[] a, int[] b) {
int answer = 0;
Arrays.sort(a);
Arrays.sort(b);
int indexB = a.length - 1;
for (int i = a.length - 1; i >= 0; i--) {
if (a[i] < b[indexB]) {
answer++;
indexB--;
}
}
return answer;
}
public int solution2(int[] a, int[] b) {
PriorityQueue<Integer> queueA = new PriorityQueue<>();
PriorityQueue<Integer> queueB = new PriorityQueue<>();
int answer = 0;
for (int i = 0; i < a.length ; i++) {
queueA.add(a[i]);
queueB.add(b[i]);
}
while (!queueB.isEmpty()&&!queueA.isEmpty()) {
if (queueA.peek() < queueB.peek()) {
answer++;
queueA.poll();
}
queueB.poll();
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/12987