mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
37 lines
2.0 KiB
HTML
37 lines
2.0 KiB
HTML
<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>
|
|
|
|
<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's ability is <strong>less than or equal to</strong> the trainer'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>
|
|
|
|
<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>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> players = [4,7,9], trainers = [8,2,5,8]
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong>
|
|
One of the ways we can form two matchings is as follows:
|
|
- players[0] can be matched with trainers[0] since 4 <= 8.
|
|
- players[1] can be matched with trainers[3] since 7 <= 8.
|
|
It can be proven that 2 is the maximum number of matchings that can be formed.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> players = [1,1,1], trainers = [10]
|
|
<strong>Output:</strong> 1
|
|
<strong>Explanation:</strong>
|
|
The trainer can be matched with any of the 3 players.
|
|
Each player can only be matched with one trainer, so the maximum answer is 1.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= players.length, trainers.length <= 10<sup>5</sup></code></li>
|
|
<li><code>1 <= players[i], trainers[j] <= 10<sup>9</sup></code></li>
|
|
</ul>
|