mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given positive integers <code>n</code> and <code>target</code>.</p>
 | 
						|
 | 
						|
<p>An array <code>nums</code> is <strong>beautiful</strong> if it meets the following conditions:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>nums.length == n</code>.</li>
 | 
						|
	<li><code>nums</code> consists of pairwise <strong>distinct</strong> <strong>positive</strong> integers.</li>
 | 
						|
	<li>There doesn't exist two <strong>distinct</strong> indices, <code>i</code> and <code>j</code>, in the range <code>[0, n - 1]</code>, such that <code>nums[i] + nums[j] == target</code>.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>Return <em>the <strong>minimum</strong> possible sum that a beautiful array could have</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 2, target = 3
 | 
						|
<strong>Output:</strong> 4
 | 
						|
<strong>Explanation:</strong> We can see that nums = [1,3] is beautiful.
 | 
						|
- The array nums has length n = 2.
 | 
						|
- The array nums consists of pairwise distinct positive integers.
 | 
						|
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
 | 
						|
It can be proven that 4 is the minimum possible sum that a beautiful array could have.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 3, target = 3
 | 
						|
<strong>Output:</strong> 8
 | 
						|
<strong>Explanation:</strong> We can see that nums = [1,3,4] is beautiful.
 | 
						|
- The array nums has length n = 3.
 | 
						|
- The array nums consists of pairwise distinct positive integers.
 | 
						|
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
 | 
						|
It can be proven that 8 is the minimum possible sum that a beautiful array could have.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 1, target = 1
 | 
						|
<strong>Output:</strong> 1
 | 
						|
<strong>Explanation:</strong> We can see, that nums = [1] is beautiful.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= n <= 10<sup>5</sup></code></li>
 | 
						|
	<li><code>1 <= target <= 10<sup>5</sup></code></li>
 | 
						|
</ul>
 |