mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										36
									
								
								算法题(国外版)/boats-to-save-people.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								算法题(国外版)/boats-to-save-people.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
<p>You are given an array <code>people</code> where <code>people[i]</code> is the weight of the <code>i<sup>th</sup></code> person, and an <strong>infinite number of boats</strong> where each boat can carry a maximum weight of <code>limit</code>. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most <code>limit</code>.</p>
 | 
			
		||||
 | 
			
		||||
<p>Return <em>the minimum number of boats to carry every given person</em>.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> people = [1,2], limit = 3
 | 
			
		||||
<strong>Output:</strong> 1
 | 
			
		||||
<strong>Explanation:</strong> 1 boat (1, 2)
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> people = [3,2,2,1], limit = 3
 | 
			
		||||
<strong>Output:</strong> 3
 | 
			
		||||
<strong>Explanation:</strong> 3 boats (1, 2), (2) and (3)
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 3:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> people = [3,5,3,4], limit = 5
 | 
			
		||||
<strong>Output:</strong> 4
 | 
			
		||||
<strong>Explanation:</strong> 4 boats (3), (3), (4), (5)
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Constraints:</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>
 | 
			
		||||
		Reference in New Issue
	
	Block a user