-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGymClothes.java
35 lines (28 loc) · 876 Bytes
/
GymClothes.java
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
31
32
33
34
35
import java.util.Arrays;
class Solution {
public static int solution(int n, int[] lost, int[] reserve) {
int 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;
break;
}
}
}
for(int i=0; i<lost.length; i++){
for(int j=0; j<reserve.length; j++){
if(lost[i]-1 == reserve[j] || lost[i] +1 == reserve[j]){
answer ++;
reserve[j] = -1;
break;
}
}
}
return answer;
}
}