mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 08:21:41 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>一个房间里有 <code>n</code> 个座位和 <code>n</code> 名学生,房间用一个数轴表示。给你一个长度为 <code>n</code> 的数组 <code>seats</code> ,其中 <code>seats[i]</code> 是第 <code>i</code> 个座位的位置。同时给你一个长度为 <code>n</code> 的数组 <code>students</code> ,其中 <code>students[j]</code> 是第 <code>j</code> 位学生的位置。</p>\n\n<p>你可以执行以下操作任意次:</p>\n\n<ul>\n\t<li>增加或者减少第 <code>i</code> 位学生的位置,每次变化量为 <code>1</code> (也就是将第 <code>i</code> 位学生从位置 <code>x</code> 移动到 <code>x + 1</code> 或者 <code>x - 1</code>)</li>\n</ul>\n\n<p>请你返回使所有学生都有座位坐的 <strong>最少移动次数</strong> ,并确保没有两位学生的座位相同。</p>\n\n<p>请注意,初始时有可能有多个座位或者多位学生在 <strong>同一</strong> 位置。</p>\n\n<p> </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> </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 <= n <= 100</code></li>\n\t<li><code>1 <= seats[i], students[j] <= 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?",
|
||||
|
Reference in New Issue
Block a user