mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 00:11:41 +08:00
移除零宽空格
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
"boundTopicId": 680477,
|
||||
"title": "Minimum Number of Operations to Reinitialize a Permutation",
|
||||
"titleSlug": "minimum-number-of-operations-to-reinitialize-a-permutation",
|
||||
"content": "<p>You are given an <strong>even</strong> integer <code>n</code>. You initially have a permutation <code>perm</code> of size <code>n</code> where <code>perm[i] == i</code> <strong>(0-indexed)</strong>.</p>\n\n<p>In one operation, you will create a new array <code>arr</code>, and for each <code>i</code>:</p>\n\n<ul>\n\t<li>If <code>i % 2 == 0</code>, then <code>arr[i] = perm[i / 2]</code>.</li>\n\t<li>If <code>i % 2 == 1</code>, then <code>arr[i] = perm[n / 2 + (i - 1) / 2]</code>.</li>\n</ul>\n\n<p>You will then assign <code>arr</code> to <code>perm</code>.</p>\n\n<p>Return <em>the minimum <strong>non-zero</strong> number of operations you need to perform on </em><code>perm</code><em> to return the permutation to its initial value.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> perm = [0,1] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,1]\nSo it takes only 1 operation.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> perm = [0,1,2,3] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,2,1,3]\nAfter the 2<sup>nd</sup> operation, perm = [0,1,2,3]\nSo it takes only 2 operations.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6\n<strong>Output:</strong> 4\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>n</code> is even.</li>\n</ul>\n",
|
||||
"content": "<p>You are given an <strong>even</strong> integer <code>n</code>. You initially have a permutation <code>perm</code> of size <code>n</code> where <code>perm[i] == i</code> <strong>(0-indexed)</strong>.</p>\n\n<p>In one operation, you will create a new array <code>arr</code>, and for each <code>i</code>:</p>\n\n<ul>\n\t<li>If <code>i % 2 == 0</code>, then <code>arr[i] = perm[i / 2]</code>.</li>\n\t<li>If <code>i % 2 == 1</code>, then <code>arr[i] = perm[n / 2 + (i - 1) / 2]</code>.</li>\n</ul>\n\n<p>You will then assign <code>arr</code> to <code>perm</code>.</p>\n\n<p>Return <em>the minimum <strong>non-zero</strong> number of operations you need to perform on </em><code>perm</code><em> to return the permutation to its initial value.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> perm = [0,1] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,1]\nSo it takes only 1 operation.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> perm = [0,1,2,3] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,2,1,3]\nAfter the 2<sup>nd</sup> operation, perm = [0,1,2,3]\nSo it takes only 2 operations.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6\n<strong>Output:</strong> 4\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>n</code> is even.</li>\n</ul>\n",
|
||||
"translatedTitle": "还原排列的最少操作步数",
|
||||
"translatedContent": "<p>给你一个偶数 <code>n</code> ,已知存在一个长度为 <code>n</code> 的排列 <code>perm</code> ,其中 <code>perm[i] == i</code>(下标 <strong>从 0 开始</strong> 计数)。</p>\n\n<p>一步操作中,你将创建一个新数组 <code>arr</code> ,对于每个 <code>i</code> :</p>\n\n<ul>\n\t<li>如果 <code>i % 2 == 0</code> ,那么 <code>arr[i] = perm[i / 2]</code></li>\n\t<li>如果 <code>i % 2 == 1</code> ,那么 <code>arr[i] = perm[n / 2 + (i - 1) / 2]</code></li>\n</ul>\n\n<p>然后将 <code>arr</code> 赋值给 <code>perm</code> 。</p>\n\n<p>要想使 <code>perm</code> 回到排列初始值,至少需要执行多少步操作?返回最小的 <strong>非零</strong> 操作步数。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 2\n<strong>输出:</strong>1\n<strong>解释:</strong>最初,perm = [0,1]\n第 1 步操作后,perm = [0,1]\n所以,仅需执行 1 步操作</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 4\n<strong>输出:</strong>2\n<strong>解释:</strong>最初,perm = [0,1,2,3]\n第 1 步操作后,perm = [0,2,1,3]\n第 2 步操作后,perm = [0,1,2,3]\n所以,仅需执行 2 步操作</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 6\n<strong>输出:</strong>4\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>n</code> 是一个偶数</li>\n</ul>\n",
|
||||
"translatedContent": "<p>给你一个偶数 <code>n</code> ,已知存在一个长度为 <code>n</code> 的排列 <code>perm</code> ,其中 <code>perm[i] == i</code>(下标 <strong>从 0 开始</strong> 计数)。</p>\n\n<p>一步操作中,你将创建一个新数组 <code>arr</code> ,对于每个 <code>i</code> :</p>\n\n<ul>\n\t<li>如果 <code>i % 2 == 0</code> ,那么 <code>arr[i] = perm[i / 2]</code></li>\n\t<li>如果 <code>i % 2 == 1</code> ,那么 <code>arr[i] = perm[n / 2 + (i - 1) / 2]</code></li>\n</ul>\n\n<p>然后将 <code>arr</code> 赋值给 <code>perm</code> 。</p>\n\n<p>要想使 <code>perm</code> 回到排列初始值,至少需要执行多少步操作?返回最小的 <strong>非零</strong> 操作步数。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 2\n<strong>输出:</strong>1\n<strong>解释:</strong>最初,perm = [0,1]\n第 1 步操作后,perm = [0,1]\n所以,仅需执行 1 步操作</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 4\n<strong>输出:</strong>2\n<strong>解释:</strong>最初,perm = [0,1,2,3]\n第 1 步操作后,perm = [0,2,1,3]\n第 2 步操作后,perm = [0,1,2,3]\n所以,仅需执行 2 步操作</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 6\n<strong>输出:</strong>4\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>n</code> 是一个偶数</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 108,
|
||||
|
Reference in New Issue
Block a user