mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-12-18 02:02:34 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>Alice 有一个下标从 <strong>0</strong> 开始的数组 <code>arr</code> ,由 <code>n</code> 个正整数组成。她会选择一个任意的 <strong>正整数 </strong><code>k</code> 并按下述方式创建两个下标从 <strong>0</strong> 开始的新整数数组 <code>lower</code> 和 <code>higher</code> :</p>\n\n<ol>\n\t<li>对每个满足 <code>0 <= i < n</code> 的下标 <code>i</code> ,<code>lower[i] = arr[i] - k</code></li>\n\t<li>对每个满足 <code>0 <= i < n</code> 的下标 <code>i</code> ,<code>higher[i] = arr[i] + k</code></li>\n</ol>\n\n<p>不幸地是,Alice 丢失了全部三个数组。但是,她记住了在数组 <code>lower</code> 和 <code>higher</code> 中出现的整数,但不知道每个整数属于哪个数组。请你帮助 Alice 还原原数组。</p>\n\n<p>给你一个由 2n 个整数组成的整数数组 <code>nums</code> ,其中 <strong>恰好</strong> <code>n</code> 个整数出现在 <code>lower</code> ,剩下的出现在 <code>higher</code> ,还原并返回 <strong>原数组</strong> <code>arr</code> 。如果出现答案不唯一的情况,返回 <strong>任一</strong> 有效数组。</p>\n\n<p><strong>注意:</strong>生成的测试用例保证存在 <strong>至少一个</strong> 有效数组 <code>arr</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>nums = [2,10,6,4,8,12]\n<strong>输出:</strong>[3,7,11]\n<strong>解释:</strong>\n如果 arr = [3,7,11] 且 k = 1 ,那么 lower = [2,6,10] 且 higher = [4,8,12] 。\n组合 lower 和 higher 得到 [2,6,10,4,8,12] ,这是 nums 的一个排列。\n另一个有效的数组是 arr = [5,7,9] 且 k = 3 。在这种情况下,lower = [2,4,6] 且 higher = [8,10,12] 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>nums = [1,1,3,3]\n<strong>输出:</strong>[2,2]\n<strong>解释:</strong>\n如果 arr = [2,2] 且 k = 1 ,那么 lower = [1,1] 且 higher = [3,3] 。\n组合 lower 和 higher 得到 [1,1,3,3] ,这是 nums 的一个排列。\n注意,数组不能是 [1,3] ,因为在这种情况下,获得 [1,1,3,3] 唯一可行的方案是 k = 0 。\n这种方案是无效的,k 必须是一个正整数。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>nums = [5,435]\n<strong>输出:</strong>[220]\n<strong>解释:</strong>\n唯一可行的组合是 arr = [220] 且 k = 215 。在这种情况下,lower = [5] 且 higher = [435] 。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 * n == nums.length</code></li>\n\t<li><code>1 <= n <= 1000</code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li>生成的测试用例保证存在 <strong>至少一个</strong> 有效数组 <code>arr</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 24,
|
||||
"likes": 26,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"7.7K\", \"totalAcceptedRaw\": 3130, \"totalSubmissionRaw\": 7731, \"acRate\": \"40.5%\"}",
|
||||
"stats": "{\"totalAccepted\": \"3.2K\", \"totalSubmission\": \"7.8K\", \"totalAcceptedRaw\": 3154, \"totalSubmissionRaw\": 7784, \"acRate\": \"40.5%\"}",
|
||||
"hints": [
|
||||
"If we fix the value of k, how can we check if an original array exists for the fixed k?",
|
||||
"The smallest value of nums is obtained by subtracting k from the smallest value of the original array. How can we use this to reduce the search space for finding a valid k?",
|
||||
|
||||
Reference in New Issue
Block a user