import java.util.*;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {
int l = lost.length;
Arrays.sort(lost); Arrays.sort(reserve);
for(int i=0; i<lost.length; i++) {
for(int j=0; j<reserve.length; j++) {
if(lost[i]==reserve[j]) {
lost[i] = -1; reserve[j] = -1;
l--;
break;
}
}
}
for(int i=0; i<lost.length; i++) {
if(lost[i]==-1) { continue; }
for(int j=0; j<reserve.length; j++) {
if(reserve[j]==-1) { continue; }
if(reserve[j]==lost[i]-1) {
reserve[j] = -1; lost[i] = -1;
l--;
} else if(reserve[j]==lost[i]+1) {
reserve[j] = -1; lost[i] = -1;
l--;
}
}
}
return n-l;
}
}
'Problem Solving > Programmers' 카테고리의 다른 글
[Level 1] 실패율 (0) | 2022.03.23 |
---|---|
[Level 1] 폰켓몬 (0) | 2022.03.23 |
[Level 1] 모의고사 (0) | 2022.03.23 |
[Level 1] K번째수 (0) | 2022.03.23 |
[Level 1] 완주하지 못한 선수 (0) | 2022.03.23 |