-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path870.cpp
More file actions
25 lines (25 loc) · 673 Bytes
/
Copy path870.cpp
File metadata and controls
25 lines (25 loc) · 673 Bytes
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
class Solution {
public:
vector<int> advantageCount(vector<int> &A, vector<int> &B) {
sort(A.begin(), A.end());
vector<int> ret;
for (auto b:B) {
int i = 0, j = A.size(), mid = 0;
while (i < j) {
mid = i + (j - i) / 2;
if (A[mid] > b)
j = mid;
else
i = mid + 1;
}
if (j == A.size()) {
ret.push_back(A[0]);
A.erase(A.begin());
} else {
ret.push_back(A[j]);
A.erase(A.begin() + j);
}
}
return ret;
}
};