Skip to content

Commit 28ce41d

Browse files
authored
Create 2410. Maximum Matching of Players With Trainers (#839)
2 parents 1d428e9 + 8699f9e commit 28ce41d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
static int matchPlayersAndTrainers(vector<int>& p, vector<int>& t)
4+
{
5+
const int n=p.size(), m=t.size();
6+
sort(p.begin(), p.end());
7+
sort(t.begin(), t.end());
8+
int match=0;
9+
for (int i=0, j=0; i<n && j<m; i++){
10+
const int pi=p[i];
11+
while(j<m && t[j]<pi) j++;
12+
if (j<m) {
13+
j++;
14+
match++;
15+
}
16+
}
17+
return match;
18+
}
19+
};

0 commit comments

Comments
 (0)