1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 08:21:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-03-29 16:56:27 +08:00
parent e730aa6794
commit ad15da05aa
2517 changed files with 7358 additions and 7332 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>一个房间里有 <code>n</code>&nbsp;个座位和 <code>n</code>&nbsp;名学生,房间用一个数轴表示。给你一个长度为 <code>n</code>&nbsp;的数组&nbsp;<code>seats</code>&nbsp;,其中&nbsp;<code>seats[i]</code> 是第 <code>i</code>&nbsp;个座位的位置。同时给你一个长度为 <code>n</code>&nbsp;的数组&nbsp;<code>students</code>&nbsp;,其中&nbsp;<code>students[j]</code>&nbsp;是第 <code>j</code>&nbsp;位学生的位置。</p>\n\n<p>你可以执行以下操作任意次:</p>\n\n<ul>\n\t<li>增加或者减少第&nbsp;<code>i</code>&nbsp;位学生的位置,每次变化量为 <code>1</code>&nbsp;(也就是将第 <code>i</code>&nbsp;位学生从位置 <code>x</code>&nbsp;移动到 <code>x + 1</code>&nbsp;或者 <code>x - 1</code></li>\n</ul>\n\n<p>请你返回使所有学生都有座位坐的 <strong>最少移动次数</strong>&nbsp;,并确保没有两位学生的座位相同。</p>\n\n<p>请注意,初始时有可能有多个座位或者多位学生在 <strong>同一</strong>&nbsp;位置。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><b>输入:</b>seats = [3,1,5], students = [2,7,4]\n<b>输出:</b>4\n<b>解释:</b>学生移动方式如下:\n- 第一位学生从位置 2 移动到位置 1 ,移动 1 次。\n- 第二位学生从位置 7 移动到位置 5 ,移动 2 次。\n- 第三位学生从位置 4 移动到位置 3 ,移动 1 次。\n总共 1 + 2 + 1 = 4 次移动。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><b>输入:</b>seats = [4,1,5,9], students = [1,3,2,6]\n<b>输出:</b>7\n<strong>解释:</strong>学生移动方式如下:\n- 第一位学生不移动。\n- 第二位学生从位置 3 移动到位置 4 ,移动 1 次。\n- 第三位学生从位置 2 移动到位置 5 ,移动 3 次。\n- 第四位学生从位置 6 移动到位置 9 ,移动 3 次。\n总共 0 + 1 + 3 + 3 = 7 次移动。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><b>输入:</b>seats = [2,2,6,6], students = [1,3,2,6]\n<b>输出:</b>4\n<b>解释:</b>学生移动方式如下:\n- 第一位学生从位置 1 移动到位置 2 ,移动 1 次。\n- 第二位学生从位置 3 移动到位置 6 ,移动 3 次。\n- 第三位学生不移动。\n- 第四位学生不移动。\n总共 1 + 3 + 0 + 0 = 4 次移动。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == seats.length == students.length</code></li>\n\t<li><code>1 &lt;= n &lt;= 100</code></li>\n\t<li><code>1 &lt;= seats[i], students[j] &lt;= 100</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 10,
"likes": 11,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -143,7 +143,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"5.3K\", \"totalSubmission\": \"6.4K\", \"totalAcceptedRaw\": 5259, \"totalSubmissionRaw\": 6374, \"acRate\": \"82.5%\"}",
"stats": "{\"totalAccepted\": \"5.3K\", \"totalSubmission\": \"6.4K\", \"totalAcceptedRaw\": 5295, \"totalSubmissionRaw\": 6419, \"acRate\": \"82.5%\"}",
"hints": [
"Can we sort the arrays to help solve the problem?",
"Can we greedily match each student to a seat?",