File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments