Skip to content

Commit 3e0f23e

Browse files
authored
feat: add rust solution to lc problem: No.2410 (#4564)
No.2410.Maximum Matching of Players With Trainers
1 parent b61fed3 commit 3e0f23e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/2400-2499/2410.Maximum Matching of Players With Trainers/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ function matchPlayersAndTrainers(players: number[], trainers: number[]): number
174174
}
175175
```
176176

177+
#### Rust
178+
179+
```rust
180+
impl Solution {
181+
pub fn match_players_and_trainers(mut players: Vec<i32>, mut trainers: Vec<i32>) -> i32 {
182+
players.sort();
183+
trainers.sort();
184+
let mut j = 0;
185+
let n = trainers.len();
186+
for (i, &p) in players.iter().enumerate() {
187+
while j < n && trainers[j] < p {
188+
j += 1;
189+
}
190+
if j == n {
191+
return i as i32;
192+
}
193+
j += 1;
194+
}
195+
players.len() as i32
196+
}
197+
}
198+
```
199+
177200
<!-- tabs:end -->
178201

179202
<!-- solution:end -->

solution/2400-2499/2410.Maximum Matching of Players With Trainers/README_EN.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,29 @@ function matchPlayersAndTrainers(players: number[], trainers: number[]): number
177177
}
178178
```
179179

180+
#### Rust
181+
182+
```rust
183+
impl Solution {
184+
pub fn match_players_and_trainers(mut players: Vec<i32>, mut trainers: Vec<i32>) -> i32 {
185+
players.sort();
186+
trainers.sort();
187+
let mut j = 0;
188+
let n = trainers.len();
189+
for (i, &p) in players.iter().enumerate() {
190+
while j < n && trainers[j] < p {
191+
j += 1;
192+
}
193+
if j == n {
194+
return i as i32;
195+
}
196+
j += 1;
197+
}
198+
players.len() as i32
199+
}
200+
}
201+
```
202+
180203
<!-- tabs:end -->
181204

182205
<!-- solution:end -->
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
impl Solution {
2+
pub fn match_players_and_trainers(mut players: Vec<i32>, mut trainers: Vec<i32>) -> i32 {
3+
players.sort();
4+
trainers.sort();
5+
let mut j = 0;
6+
let n = trainers.len();
7+
for (i, &p) in players.iter().enumerate() {
8+
while j < n && trainers[j] < p {
9+
j += 1;
10+
}
11+
if j == n {
12+
return i as i32;
13+
}
14+
j += 1;
15+
}
16+
players.len() as i32
17+
}
18+
}

0 commit comments

Comments
 (0)