1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/救生艇 [boats-to-save-people].html
2022-03-29 12:43:11 +08:00

40 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定数组<meta charset="UTF-8" />&nbsp;<code>people</code>&nbsp;<code>people[i]</code>表示第 <code>i</code><sup>&nbsp;</sup>个人的体重&nbsp;<strong>船的数量不限</strong>,每艘船可以承载的最大重量为&nbsp;<code>limit</code></p>
<p>每艘船最多可同时载两人,但条件是这些人的重量之和最多为&nbsp;<code>limit</code></p>
<p>返回 <em>承载所有人所需的最小船数</em>&nbsp;</p>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= people.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= people[i] &lt;= limit &lt;= 3 * 10<sup>4</sup></code></li>
</ul>