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:
2025-05-25 15:06:02 +08:00
parent 59597532bc
commit 3070bed723
272 changed files with 1031 additions and 749 deletions

View File

@@ -7,9 +7,9 @@
"boundTopicId": 722208,
"title": "Single-Threaded CPU",
"titleSlug": "single-threaded-cpu",
"content": "<p>You are given <code>n</code> tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> task will be available to process at <code>enqueueTime<sub>i</sub></code> and will take <code>processingTime<sub>i</sub></code><sub> </sub>to finish processing.</p>\n\n<p>You have a single-threaded CPU that can process <strong>at most one</strong> task at a time and will act in the following way:</p>\n\n<ul>\n\t<li>If the CPU is idle and there are no available tasks to process, the CPU remains idle.</li>\n\t<li>If the CPU is idle and there are available tasks, the CPU will choose the one with the <strong>shortest processing time</strong>. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.</li>\n\t<li>Once a task is started, the CPU will <strong>process the entire task</strong> without stopping.</li>\n\t<li>The CPU can finish a task then start a new one instantly.</li>\n</ul>\n\n<p>Return <em>the order in which the CPU will process the tasks.</em></p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,2],[2,4],[3,2],[4,1]]\n<strong>Output:</strong> [0,2,3,1]\n<strong>Explanation: </strong>The events go as follows: \n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n<strong>Output:</strong> [4,3,2,0,1]\n<strong>Explanation</strong><strong>: </strong>The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>tasks.length == n</code></li>\n\t<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= enqueueTime<sub>i</sub>, processingTime<sub>i</sub> &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"content": "<p>You are given <code>n</code> tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> task will be available to process at <code>enqueueTime<sub>i</sub></code> and will take <code>processingTime<sub>i</sub></code><sub> </sub>to finish processing.</p>\n\n<p>You have a single-threaded CPU that can process <strong>at most one</strong> task at a time and will act in the following way:</p>\n\n<ul>\n\t<li>If the CPU is idle and there are no available tasks to process, the CPU remains idle.</li>\n\t<li>If the CPU is idle and there are available tasks, the CPU will choose the one with the <strong>shortest processing time</strong>. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.</li>\n\t<li>Once a task is started, the CPU will <strong>process the entire task</strong> without stopping.</li>\n\t<li>The CPU can finish a task then start a new one instantly.</li>\n</ul>\n\n<p>Return <em>the order in which the CPU will process the tasks.</em></p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,2],[2,4],[3,2],[4,1]]\n<strong>Output:</strong> [0,2,3,1]\n<strong>Explanation: </strong>The events go as follows: \n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n<strong>Output:</strong> [4,3,2,0,1]\n<strong>Explanation</strong><strong>: </strong>The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>tasks.length == n</code></li>\n\t<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= enqueueTime<sub>i</sub>, processingTime<sub>i</sub> &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"translatedTitle": "单线程 CPU",
"translatedContent": "<p>给你一个二维数组 <code>tasks</code> ,用于表示 <code>n</code> 项从 <code>0</code> 到 <code>n - 1</code> 编号的任务。其中 <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> 意味着第 <code>i<sup></sup></code> 项任务将会于 <code>enqueueTime<sub>i</sub></code> 时进入任务队列,需要 <code>processingTime<sub>i</sub></code><sub> </sub>的时长完成执行。</p>\n\n<p>现有一个单线程 CPU ,同一时间只能执行 <strong>最多一项</strong> 任务,该 CPU 将会按照下述方式运行:</p>\n\n<ul>\n\t<li>如果 CPU 空闲,且任务队列中没有需要执行的任务,则 CPU 保持空闲状态。</li>\n\t<li>如果 CPU 空闲,但任务队列中有需要执行的任务,则 CPU 将会选择 <strong>执行时间最短</strong> 的任务开始执行。如果多个任务具有同样的最短执行时间,则选择下标最小的任务开始执行。</li>\n\t<li>一旦某项任务开始执行CPU 在 <strong>执行完整个任务</strong> 前都不会停止。</li>\n\t<li>CPU 可以在完成一项任务后,立即开始执行一项新任务。</li>\n</ul>\n\n<p>返回<em> </em>CPU<em> </em>处理任务的顺序。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>tasks = [[1,2],[2,4],[3,2],[4,1]]\n<strong>输出:</strong>[0,2,3,1]\n<strong>解释:</strong>事件按下述流程运行: \n- time = 1 ,任务 0 进入任务队列,可执行任务项 = {0}\n- 同样在 time = 1 ,空闲状态的 CPU 开始执行任务 0 ,可执行任务项 = {}\n- time = 2 ,任务 1 进入任务队列,可执行任务项 = {1}\n- time = 3 ,任务 2 进入任务队列,可执行任务项 = {1, 2}\n- 同样在 time = 3 CPU 完成任务 0 并开始执行队列中用时最短的任务 2 ,可执行任务项 = {1}\n- time = 4 ,任务 3 进入任务队列,可执行任务项 = {1, 3}\n- time = 5 CPU 完成任务 2 并开始执行队列中用时最短的任务 3 ,可执行任务项 = {1}\n- time = 6 CPU 完成任务 3 并开始执行任务 1 ,可执行任务项 = {}\n- time = 10 CPU 完成任务 1 并进入空闲状态\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n<strong>输出:</strong>[4,3,2,0,1]\n<strong>解释:</strong>事件按下述流程运行: \n- time = 7 ,所有任务同时进入任务队列,可执行任务项 = {0,1,2,3,4}\n- 同样在 time = 7 ,空闲状态的 CPU 开始执行任务 4 ,可执行任务项 = {0,1,2,3}\n- time = 9 CPU 完成任务 4 并开始执行任务 3 ,可执行任务项 = {0,1,2}\n- time = 13 CPU 完成任务 3 并开始执行任务 2 ,可执行任务项 = {0,1}\n- time = 18 CPU 完成任务 2 并开始执行任务 0 ,可执行任务项 = {1}\n- time = 28 CPU 完成任务 0 并开始执行任务 1 ,可执行任务项 = {}\n- time = 40 CPU 完成任务 1 并进入空闲状态</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>tasks.length == n</code></li>\n\t<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= enqueueTime<sub>i</sub>, processingTime<sub>i</sub> &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"translatedContent": "<p>给你一个二维数组 <code>tasks</code> ,用于表示 <code>n</code> 项从 <code>0</code> 到 <code>n - 1</code> 编号的任务。其中 <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> 意味着第 <code>i<sup></sup></code> 项任务将会于 <code>enqueueTime<sub>i</sub></code> 时进入任务队列,需要 <code>processingTime<sub>i</sub></code><sub> </sub>的时长完成执行。</p>\n\n<p>现有一个单线程 CPU ,同一时间只能执行 <strong>最多一项</strong> 任务,该 CPU 将会按照下述方式运行:</p>\n\n<ul>\n\t<li>如果 CPU 空闲,且任务队列中没有需要执行的任务,则 CPU 保持空闲状态。</li>\n\t<li>如果 CPU 空闲,但任务队列中有需要执行的任务,则 CPU 将会选择 <strong>执行时间最短</strong> 的任务开始执行。如果多个任务具有同样的最短执行时间,则选择下标最小的任务开始执行。</li>\n\t<li>一旦某项任务开始执行CPU 在 <strong>执行完整个任务</strong> 前都不会停止。</li>\n\t<li>CPU 可以在完成一项任务后,立即开始执行一项新任务。</li>\n</ul>\n\n<p>返回<em> </em>CPU<em> </em>处理任务的顺序。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>tasks = [[1,2],[2,4],[3,2],[4,1]]\n<strong>输出:</strong>[0,2,3,1]\n<strong>解释:</strong>事件按下述流程运行: \n- time = 1 ,任务 0 进入任务队列,可执行任务项 = {0}\n- 同样在 time = 1 ,空闲状态的 CPU 开始执行任务 0 ,可执行任务项 = {}\n- time = 2 ,任务 1 进入任务队列,可执行任务项 = {1}\n- time = 3 ,任务 2 进入任务队列,可执行任务项 = {1, 2}\n- 同样在 time = 3 CPU 完成任务 0 并开始执行队列中用时最短的任务 2 ,可执行任务项 = {1}\n- time = 4 ,任务 3 进入任务队列,可执行任务项 = {1, 3}\n- time = 5 CPU 完成任务 2 并开始执行队列中用时最短的任务 3 ,可执行任务项 = {1}\n- time = 6 CPU 完成任务 3 并开始执行任务 1 ,可执行任务项 = {}\n- time = 10 CPU 完成任务 1 并进入空闲状态\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n<strong>输出:</strong>[4,3,2,0,1]\n<strong>解释:</strong>事件按下述流程运行: \n- time = 7 ,所有任务同时进入任务队列,可执行任务项 = {0,1,2,3,4}\n- 同样在 time = 7 ,空闲状态的 CPU 开始执行任务 4 ,可执行任务项 = {0,1,2,3}\n- time = 9 CPU 完成任务 4 并开始执行任务 3 ,可执行任务项 = {0,1,2}\n- time = 13 CPU 完成任务 3 并开始执行任务 2 ,可执行任务项 = {0,1}\n- time = 18 CPU 完成任务 2 并开始执行任务 0 ,可执行任务项 = {1}\n- time = 28 CPU 完成任务 0 并开始执行任务 1 ,可执行任务项 = {}\n- time = 40 CPU 完成任务 1 并进入空闲状态</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>tasks.length == n</code></li>\n\t<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= enqueueTime<sub>i</sub>, processingTime<sub>i</sub> &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 122,