나의 풀이
import java.util.*;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {
Set<Integer> reserveOnly = new HashSet<>();
for (int r : reserve) {
reserveOnly.add(r);
}
for (int l : lost) {
reserveOnly.remove(l);
}
Set<Integer> lostOnly = new HashSet<>();
for (int l : lost) {
lostOnly.add(l);
}
for (int r : reserve) {
lostOnly.remove(r);
}
for (int reserveNum : reserveOnly) {
int front = reserveNum - 1;
int back = reserveNum + 1;
if (lostOnly.contains(front)) {
lostOnly.remove(front);
} else if (lostOnly.contains(back)) {
lostOnly.remove(back);
}
}
int answer = n - lostOnly.size();
return answer;
}
}