Skip to content

Commit 72e7b07

Browse files
committed
test: [20250713] Add (2410)
1 parent 1dbd44d commit 72e7b07

File tree

15 files changed

+235
-5
lines changed

15 files changed

+235
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ members = [
254254
"problems/problems_3440",
255255
"problems/problems_3169",
256256
"problems/problems_1900",
257+
"problems/problems_2410",
257258
]
258259

259260
[package]
@@ -530,3 +531,4 @@ solution_3439 = { path = "problems/problems_3439", features = ["solution_3439"]
530531
solution_3440 = { path = "problems/problems_3440", features = ["solution_3440"] }
531532
solution_3169 = { path = "problems/problems_3169", features = ["solution_3169"] }
532533
solution_1900 = { path = "problems/problems_1900", features = ["solution_1900"] }
534+
solution_2410 = { path = "problems/problems_2410", features = ["solution_2410"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "1592",
2+
"daily": "2410",
33
"plans": ["3602", "problems", "3603", "problems", "3604", "problems", "3605", "problems", "3606", "problems", "3607", "problems", "3608", "problems", "3609", "problems"]
44
}

golang/solution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package golang
22

33
import (
4-
problem "leetCode/problems/problems_1592"
4+
problem "leetCode/problems/problems_2410"
55
"testing"
66
)
77

88
func TestSolution(t *testing.T) {
9-
TestEach(t, "1592", "problems", problem.Solve)
9+
TestEach(t, "2410", "problems", problem.Solve)
1010
}

problems/problems_2410/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "solution_2410"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 2410 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_2410 = []
12+
13+
[dependencies]
14+
serde_json = "1.0"
15+
rand = "0.8.4"
16+
regex = "1.10.5"
17+
library = { path = "../../rust/library", features = ["model"] }
18+
19+
[lib]
20+
name = "solution_2410"
21+
path = "solution.rs"

problems/problems_2410/Solution.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
5+
using namespace std;
6+
using json = nlohmann::json;
7+
8+
class Solution {
9+
public:
10+
int matchPlayersAndTrainers(vector<int>& players, vector<int>& trainers) {
11+
12+
}
13+
};
14+
15+
json leetcode::qubh::Solve(string input_json_values) {
16+
vector<string> inputArray;
17+
size_t pos = input_json_values.find('\n');
18+
while (pos != string::npos) {
19+
inputArray.push_back(input_json_values.substr(0, pos));
20+
input_json_values = input_json_values.substr(pos + 1);
21+
pos = input_json_values.find('\n');
22+
}
23+
inputArray.push_back(input_json_values);
24+
25+
Solution solution;
26+
vector<int> players = json::parse(inputArray.at(0));
27+
vector<int> trainers = json::parse(inputArray.at(1));
28+
return solution.matchPlayersAndTrainers(players, trainers);
29+
}

problems/problems_2410/Solution.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package problems.problems_2410;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import java.util.*;
5+
import qubhjava.BaseSolution;
6+
7+
8+
public class Solution extends BaseSolution {
9+
public int matchPlayersAndTrainers(int[] players, int[] trainers) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
int[] players = jsonArrayToIntArray(inputJsonValues[0]);
16+
int[] trainers = jsonArrayToIntArray(inputJsonValues[1]);
17+
return JSON.toJSON(matchPlayersAndTrainers(players, trainers));
18+
}
19+
}

problems/problems_2410/problem.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 2410. Maximum Matching of Players With Trainers [Rating: 1381.09]
2+
3+
<p>You are given a <strong>0-indexed</strong> integer array <code>players</code>, where <code>players[i]</code> represents the <strong>ability</strong> of the <code>i<sup>th</sup></code> player. You are also given a <strong>0-indexed</strong> integer array <code>trainers</code>, where <code>trainers[j]</code> represents the <strong>training capacity </strong>of the <code>j<sup>th</sup></code> trainer.</p>
4+
5+
<p>The <code>i<sup>th</sup></code> player can <strong>match</strong> with the <code>j<sup>th</sup></code> trainer if the player&#39;s ability is <strong>less than or equal to</strong> the trainer&#39;s training capacity. Additionally, the <code>i<sup>th</sup></code> player can be matched with at most one trainer, and the <code>j<sup>th</sup></code> trainer can be matched with at most one player.</p>
6+
7+
<p>Return <em>the <strong>maximum</strong> number of matchings between </em><code>players</code><em> and </em><code>trainers</code><em> that satisfy these conditions.</em></p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
<pre>
13+
<strong>Input:</strong> players = [4,7,9], trainers = [8,2,5,8]
14+
<strong>Output:</strong> 2
15+
<strong>Explanation:</strong>
16+
One of the ways we can form two matchings is as follows:
17+
- players[0] can be matched with trainers[0] since 4 &lt;= 8.
18+
- players[1] can be matched with trainers[3] since 7 &lt;= 8.
19+
It can be proven that 2 is the maximum number of matchings that can be formed.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> players = [1,1,1], trainers = [10]
26+
<strong>Output:</strong> 1
27+
<strong>Explanation:</strong>
28+
The trainer can be matched with any of the 3 players.
29+
Each player can only be matched with one trainer, so the maximum answer is 1.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= players.length, trainers.length &lt;= 10<sup>5</sup></code></li>
37+
<li><code>1 &lt;= players[i], trainers[j] &lt;= 10<sup>9</sup></code></li>
38+
</ul>
39+
40+
<p>&nbsp;</p>
41+
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/assign-cookies/description/" target="_blank"> 445: Assign Cookies.</a></p>

problems/problems_2410/problem_zh.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 2410. 运动员和训练师的最大匹配数 [难度分: 1381.09]
2+
3+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>players</code>&nbsp;,其中&nbsp;<code>players[i]</code>&nbsp;表示第 <code>i</code>&nbsp;名运动员的 <strong>能力</strong>&nbsp;值,同时给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>trainers</code>&nbsp;,其中&nbsp;<code>trainers[j]</code>&nbsp;表示第 <code>j</code>&nbsp;名训练师的 <strong>训练能力值</strong>&nbsp;。</p>
4+
5+
<p>如果第 <code>i</code>&nbsp;名运动员的能力值 <strong>小于等于</strong>&nbsp;第 <code>j</code>&nbsp;名训练师的能力值,那么第&nbsp;<code>i</code>&nbsp;名运动员可以 <strong>匹配</strong>&nbsp;&nbsp;<code>j</code>&nbsp;名训练师。除此以外,每名运动员至多可以匹配一位训练师,每位训练师最多可以匹配一位运动员。</p>
6+
7+
<p>请你返回满足上述要求&nbsp;<code>players</code>&nbsp;和 <code>trainers</code>&nbsp;的 <strong>最大</strong> 匹配数。</p>
8+
9+
<p>&nbsp;</p>
10+
11+
<p><strong>示例 1:</strong></p>
12+
13+
<pre><strong>输入:</strong>players = [4,7,9], trainers = [8,2,5,8]
14+
<b>输出:</b>2
15+
<b>解释:</b>
16+
得到两个匹配的一种方案是:
17+
- players[0] 与 trainers[0] 匹配,因为 4 &lt;= 8 。
18+
- players[1] 与 trainers[3] 匹配,因为 7 &lt;= 8 。
19+
可以证明 2 是可以形成的最大匹配数。
20+
</pre>
21+
22+
<p><strong>示例 2:</strong></p>
23+
24+
<pre><b>输入:</b>players = [1,1,1], trainers = [10]
25+
<b>输出:</b>1
26+
<b>解释:</b>
27+
训练师可以匹配所有 3 个运动员
28+
每个运动员至多只能匹配一个训练师,所以最大答案是 1 。
29+
</pre>
30+
31+
<p>&nbsp;</p>
32+
33+
<p><strong>提示:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= players.length, trainers.length &lt;= 10<sup>5</sup></code></li>
37+
<li><code>1 &lt;= players[i], trainers[j] &lt;= 10<sup>9</sup></code></li>
38+
</ul>

problems/problems_2410/solution.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package problem2410
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"strings"
7+
)
8+
9+
func matchPlayersAndTrainers(players []int, trainers []int) int {
10+
11+
}
12+
13+
func Solve(inputJsonValues string) any {
14+
inputValues := strings.Split(inputJsonValues, "\n")
15+
var players []int
16+
var trainers []int
17+
18+
if err := json.Unmarshal([]byte(inputValues[0]), &players); err != nil {
19+
log.Fatal(err)
20+
}
21+
if err := json.Unmarshal([]byte(inputValues[1]), &trainers); err != nil {
22+
log.Fatal(err)
23+
}
24+
25+
return matchPlayersAndTrainers(players, trainers)
26+
}

problems/problems_2410/solution.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import solution
2+
from typing import *
3+
4+
5+
class Solution(solution.Solution):
6+
def solve(self, test_input=None):
7+
return self.matchPlayersAndTrainers(*test_input)
8+
9+
def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int:
10+
pass
11+

0 commit comments

Comments
 (0)