mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
40 lines
1.2 KiB
HTML
40 lines
1.2 KiB
HTML
<p>给定数组<meta charset="UTF-8" /> <code>people</code> 。<code>people[i]</code>表示第 <code>i</code><sup> </sup>个人的体重 ,<strong>船的数量不限</strong>,每艘船可以承载的最大重量为 <code>limit</code>。</p>
|
||
|
||
<p>每艘船最多可同时载两人,但条件是这些人的重量之和最多为 <code>limit</code>。</p>
|
||
|
||
<p>返回 <em>承载所有人所需的最小船数</em> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>people = [1,2], limit = 3
|
||
<strong>输出:</strong>1
|
||
<strong>解释:</strong>1 艘船载 (1, 2)
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>people = [3,2,2,1], limit = 3
|
||
<strong>输出:</strong>3
|
||
<strong>解释:</strong>3 艘船分别载 (1, 2), (2) 和 (3)
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>people = [3,5,3,4], limit = 5
|
||
<strong>输出:</strong>4
|
||
<strong>解释:</strong>4 艘船分别载 (3), (3), (4), (5)</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= people.length <= 5 * 10<sup>4</sup></code></li>
|
||
<li><code>1 <= people[i] <= limit <= 3 * 10<sup>4</sup></code></li>
|
||
</ul>
|