We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3d9ac67 commit a2b5ed0Copy full SHA for a2b5ed0
1 file changed
lkhyun/202511/07 PGM Lv2 숫자 게임.md
@@ -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
37
+ right = mid;
38
39
40
41
+ return left;
42
43
+}
44
+```
0 commit comments