1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| import java.util.*;
class Solution {
public int solution(int n, int[] lost, int[] reserve) {
int answer = 0;
answer = n -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]){
answer++;
lost[i] = -1;
reserve[j] = -1;
}
}
}
for(int i=0; i<lost.length; i++){
for(int j =0; j<reserve.length; j++){
if(lost[i] == reserve[j]+1 || lost[i] == reserve[j]-1 ){
answer++;
lost[i] = -1;
reserve[j] = -1;
}
}
}
return answer;
}
}
|