mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>The <strong>pair sum</strong> of a pair <code>(a,b)</code> is equal to <code>a + b</code>. The <strong>maximum pair sum</strong> is the largest <strong>pair sum</strong> in a list of pairs.</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<ul>
 | 
						|
 | 
						|
	<li>For example, if we have pairs <code>(1,5)</code>, <code>(2,3)</code>, and <code>(4,4)</code>, the <strong>maximum pair sum</strong> would be <code>max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8</code>.</li>
 | 
						|
 | 
						|
</ul>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p>Given an array <code>nums</code> of <strong>even</strong> length <code>n</code>, pair up the elements of <code>nums</code> into <code>n / 2</code> pairs such that:</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<ul>
 | 
						|
 | 
						|
	<li>Each element of <code>nums</code> is in <strong>exactly one</strong> pair, and</li>
 | 
						|
 | 
						|
	<li>The <strong>maximum pair sum </strong>is <strong>minimized</strong>.</li>
 | 
						|
 | 
						|
</ul>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p>Return <em>the minimized <strong>maximum pair sum</strong> after optimally pairing up the elements</em>.</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
<strong>Input:</strong> nums = [3,5,2,3]
 | 
						|
 | 
						|
<strong>Output:</strong> 7
 | 
						|
 | 
						|
<strong>Explanation:</strong> The elements can be paired up into pairs (3,3) and (5,2).
 | 
						|
 | 
						|
The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
<strong>Input:</strong> nums = [3,5,4,2,4,6]
 | 
						|
 | 
						|
<strong>Output:</strong> 8
 | 
						|
 | 
						|
<strong>Explanation:</strong> The elements can be paired up into pairs (3,5), (4,4), and (6,2).
 | 
						|
 | 
						|
The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<ul>
 | 
						|
 | 
						|
	<li><code>n == nums.length</code></li>
 | 
						|
 | 
						|
	<li><code>2 <= n <= 10<sup>5</sup></code></li>
 | 
						|
 | 
						|
	<li><code>n</code> is <strong>even</strong>.</li>
 | 
						|
 | 
						|
	<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
 | 
						|
 | 
						|
</ul> |