Skip to content

Commit a2b5ed0

Browse files
authored
[20251107] PGM / Lv3 / 숫자 게임 / 이강현
1 parent 3d9ac67 commit a2b5ed0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int[] A, int[] B) {
6+
int answer = 0;
7+
8+
List<Integer> listB = new ArrayList<>();
9+
for (int num : B) {
10+
listB.add(num);
11+
}
12+
Collections.sort(listB);
13+
14+
for (int cur : A) {
15+
int idx = binarySearch(listB, cur);
16+
17+
if (idx < listB.size()) {
18+
answer++;
19+
listB.remove(idx);
20+
} else {
21+
listB.remove(0);
22+
}
23+
}
24+
25+
return answer;
26+
}
27+
private int binarySearch(List<Integer> list, int target) {
28+
int left = 0;
29+
int right = list.size();
30+
31+
while (left < right) {
32+
int mid = (left + right) / 2;
33+
34+
if (list.get(mid) <= target) {
35+
left = mid + 1;
36+
} else {
37+
right = mid;
38+
}
39+
}
40+
41+
return left;
42+
}
43+
}
44+
```

0 commit comments

Comments
 (0)