1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-25 23:08:57 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个长度为<strong> 偶数</strong> <code>n</code> 的整数数组 <code>nums</code> 和一个整数 <code>limit</code> 。每一次操作,你可以将 <code>nums</code> 中的任何整数替换为 <code>1</code> 到 <code>limit</code> 之间的另一个整数。</p>\n\n<p>如果对于所有下标 <code>i</code><strong>下标从 </strong><code>0</code><strong> 开始</strong><code>nums[i] + nums[n - 1 - i]</code> 都等于同一个数,则数组 <code>nums</code> 是 <strong>互补的</strong> 。例如,数组 <code>[1,2,3,4]</code> 是互补的,因为对于所有下标 <code>i</code> <code>nums[i] + nums[n - 1 - i] = 5</code> 。</p>\n\n<p>返回使数组 <strong>互补</strong> 的 <strong>最少</strong> 操作次数。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,2,4,3], limit = 4\n<strong>输出:</strong>1\n<strong>解释:</strong>经过 1 次操作,你可以将数组 nums 变成 [1,2,<strong>2</strong>,3](加粗元素是变更的数字):\nnums[0] + nums[3] = 1 + 3 = 4.\nnums[1] + nums[2] = 2 + 2 = 4.\nnums[2] + nums[1] = 2 + 2 = 4.\nnums[3] + nums[0] = 3 + 1 = 4.\n对于每个 i nums[i] + nums[n-1-i] = 4 ,所以 nums 是互补的。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,2,2,1], limit = 2\n<strong>输出:</strong>2\n<strong>解释:</strong>经过 2 次操作,你可以将数组 nums 变成 [<strong>2</strong>,2,2,<strong>2</strong>] 。你不能将任何数字变更为 3 ,因为 3 > limit 。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,2,1,2], limit = 2\n<strong>输出:</strong>0\n<strong>解释:</strong>nums 已经是互补的。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == nums.length</code></li>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= limit <= 10<sup>5</sup></code></li>\n\t<li><code>n</code> 是偶数。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 75,
"likes": 77,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"7.6K\", \"totalAcceptedRaw\": 2873, \"totalSubmissionRaw\": 7567, \"acRate\": \"38.0%\"}",
"stats": "{\"totalAccepted\": \"3K\", \"totalSubmission\": \"7.8K\", \"totalAcceptedRaw\": 2996, \"totalSubmissionRaw\": 7775, \"acRate\": \"38.5%\"}",
"hints": [
"Given a target sum x, each pair of nums[i] and nums[n-1-i] would either need 0, 1, or 2 modifications.",
"Can you find the optimal target sum x value such that the sum of modifications is minimized?",