1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-08 08:51:42 +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": 489750,
"title": "Minimum Initial Energy to Finish Tasks",
"titleSlug": "minimum-initial-energy-to-finish-tasks",
"content": "<p>You are given an array <code>tasks</code> where <code>tasks[i] = [actual<sub>i</sub>, minimum<sub>i</sub>]</code>:</p>\n\n<ul>\n\t<li><code>actual<sub>i</sub></code> is the actual amount of energy you <strong>spend to finish</strong> the <code>i<sup>th</sup></code> task.</li>\n\t<li><code>minimum<sub>i</sub></code> is the minimum amount of energy you <strong>require to begin</strong> the <code>i<sup>th</sup></code> task.</li>\n</ul>\n\n<p>For example, if the task is <code>[10, 12]</code> and your current energy is <code>11</code>, you cannot start this task. However, if your current energy is <code>13</code>, you can complete this task, and your energy will be <code>3</code> after finishing it.</p>\n\n<p>You can finish the tasks in <strong>any order</strong> you like.</p>\n\n<p>Return <em>the <strong>minimum</strong> initial amount of energy you will need</em> <em>to finish all 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],[4,8]]\n<strong>Output:</strong> 8\n<strong>Explanation:</strong>\nStarting with 8 energy, we finish the tasks in the following order:\n - 3rd task. Now energy = 8 - 4 = 4.\n - 2nd task. Now energy = 4 - 2 = 2.\n - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n<strong>Output:</strong> 32\n<strong>Explanation:</strong>\nStarting with 32 energy, we finish the tasks in the following order:\n - 1st task. Now energy = 32 - 1 = 31.\n - 2nd task. Now energy = 31 - 2 = 29.\n - 3rd task. Now energy = 29 - 10 = 19.\n - 4th task. Now energy = 19 - 10 = 9.\n - 5th task. Now energy = 9 - 8 = 1.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n<strong>Output:</strong> 27\n<strong>Explanation:</strong>\nStarting with 27 energy, we finish the tasks in the following order:\n - 5th task. Now energy = 27 - 5 = 22.\n - 2nd task. Now energy = 22 - 2 = 20.\n - 3rd task. Now energy = 20 - 3 = 17.\n - 1st task. Now energy = 17 - 1 = 16.\n - 4th task. Now energy = 16 - 4 = 12.\n - 6th task. Now energy = 12 - 6 = 6.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= actual<sub>i</sub>&nbsp;&lt;= minimum<sub>i</sub>&nbsp;&lt;= 10<sup>4</sup></code></li>\n</ul>\n",
"content": "<p>You are given an array <code>tasks</code> where <code>tasks[i] = [actual<sub>i</sub>, minimum<sub>i</sub>]</code>:</p>\n\n<ul>\n\t<li><code>actual<sub>i</sub></code> is the actual amount of energy you <strong>spend to finish</strong> the <code>i<sup>th</sup></code> task.</li>\n\t<li><code>minimum<sub>i</sub></code> is the minimum amount of energy you <strong>require to begin</strong> the <code>i<sup>th</sup></code> task.</li>\n</ul>\n\n<p>For example, if the task is <code>[10, 12]</code> and your current energy is <code>11</code>, you cannot start this task. However, if your current energy is <code>13</code>, you can complete this task, and your energy will be <code>3</code> after finishing it.</p>\n\n<p>You can finish the tasks in <strong>any order</strong> you like.</p>\n\n<p>Return <em>the <strong>minimum</strong> initial amount of energy you will need</em> <em>to finish all 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],[4,8]]\n<strong>Output:</strong> 8\n<strong>Explanation:</strong>\nStarting with 8 energy, we finish the tasks in the following order:\n - 3rd task. Now energy = 8 - 4 = 4.\n - 2nd task. Now energy = 4 - 2 = 2.\n - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n<strong>Output:</strong> 32\n<strong>Explanation:</strong>\nStarting with 32 energy, we finish the tasks in the following order:\n - 1st task. Now energy = 32 - 1 = 31.\n - 2nd task. Now energy = 31 - 2 = 29.\n - 3rd task. Now energy = 29 - 10 = 19.\n - 4th task. Now energy = 19 - 10 = 9.\n - 5th task. Now energy = 9 - 8 = 1.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n<strong>Output:</strong> 27\n<strong>Explanation:</strong>\nStarting with 27 energy, we finish the tasks in the following order:\n - 5th task. Now energy = 27 - 5 = 22.\n - 2nd task. Now energy = 22 - 2 = 20.\n - 3rd task. Now energy = 20 - 3 = 17.\n - 1st task. Now energy = 17 - 1 = 16.\n - 4th task. Now energy = 16 - 4 = 12.\n - 6th task. Now energy = 12 - 6 = 6.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= actual<sub>i</sub>&nbsp;&lt;= minimum<sub>i</sub>&nbsp;&lt;= 10<sup>4</sup></code></li>\n</ul>\n",
"translatedTitle": "完成所有任务的最少初始能量",
"translatedContent": "<p>给你一个任务数组 <code>tasks</code> ,其中 <code>tasks[i] = [actual<sub>i</sub>, minimum<sub>i</sub>]</code> </p>\n\n<ul>\n\t<li><code>actual<sub>i</sub></code> 是完成第 <code>i</code> 个任务 <strong>需要耗费</strong> 的实际能量。</li>\n\t<li><code>minimum<sub>i</sub></code> 是开始第 <code>i</code> 个任务前需要达到的最低能量。</li>\n</ul>\n\n<p>比方说,如果任务为 <code>[10, 12]</code> 且你当前的能量为 <code>11</code> ,那么你不能开始这个任务。如果你当前的能量为 <code>13</code> ,你可以完成这个任务,且完成它后剩余能量为 <code>3</code> 。</p>\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>tasks = [[1,2],[2,4],[4,8]]\n<b>输出:</b>8\n<strong>解释:</strong>\n一开始有 8 能量,我们按照如下顺序完成任务:\n - 完成第 3 个任务,剩余能量为 8 - 4 = 4 。\n - 完成第 2 个任务,剩余能量为 4 - 2 = 2 。\n - 完成第 1 个任务,剩余能量为 2 - 1 = 1 。\n注意到尽管我们有能量剩余但是如果一开始只有 7 能量是不能完成所有任务的,因为我们无法开始第 3 个任务。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><b>输入:</b>tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n<b>输出:</b>32\n<strong>解释:</strong>\n一开始有 32 能量,我们按照如下顺序完成任务:\n - 完成第 1 个任务,剩余能量为 32 - 1 = 31 。\n - 完成第 2 个任务,剩余能量为 31 - 2 = 29 。\n - 完成第 3 个任务,剩余能量为 29 - 10 = 19 。\n - 完成第 4 个任务,剩余能量为 19 - 10 = 9 。\n - 完成第 5 个任务,剩余能量为 9 - 8 = 1 。</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><b>输入:</b>tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n<b>输出:</b>27\n<strong>解释:</strong>\n一开始有 27 能量,我们按照如下顺序完成任务:\n - 完成第 5 个任务,剩余能量为 27 - 5 = 22 。\n - 完成第 2 个任务,剩余能量为 22 - 2 = 20 。\n - 完成第 3 个任务,剩余能量为 20 - 3 = 17 。\n - 完成第 1 个任务,剩余能量为 17 - 1 = 16 。\n - 完成第 4 个任务,剩余能量为 16 - 4 = 12 。\n - 完成第 6 个任务,剩余能量为 12 - 6 = 6 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= actual<sub>i</sub> &lt;= minimum<sub>i</sub> &lt;= 10<sup>4</sup></code></li>\n</ul>\n",
"translatedContent": "<p>给你一个任务数组 <code>tasks</code> ,其中 <code>tasks[i] = [actual<sub>i</sub>, minimum<sub>i</sub>]</code> </p>\n\n<ul>\n\t<li><code>actual<sub>i</sub></code> 是完成第 <code>i</code> 个任务 <strong>需要耗费</strong> 的实际能量。</li>\n\t<li><code>minimum<sub>i</sub></code> 是开始第 <code>i</code> 个任务前需要达到的最低能量。</li>\n</ul>\n\n<p>比方说,如果任务为 <code>[10, 12]</code> 且你当前的能量为 <code>11</code> ,那么你不能开始这个任务。如果你当前的能量为 <code>13</code> ,你可以完成这个任务,且完成它后剩余能量为 <code>3</code> 。</p>\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>tasks = [[1,2],[2,4],[4,8]]\n<b>输出:</b>8\n<strong>解释:</strong>\n一开始有 8 能量,我们按照如下顺序完成任务:\n - 完成第 3 个任务,剩余能量为 8 - 4 = 4 。\n - 完成第 2 个任务,剩余能量为 4 - 2 = 2 。\n - 完成第 1 个任务,剩余能量为 2 - 1 = 1 。\n注意到尽管我们有能量剩余但是如果一开始只有 7 能量是不能完成所有任务的,因为我们无法开始第 3 个任务。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><b>输入:</b>tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n<b>输出:</b>32\n<strong>解释:</strong>\n一开始有 32 能量,我们按照如下顺序完成任务:\n - 完成第 1 个任务,剩余能量为 32 - 1 = 31 。\n - 完成第 2 个任务,剩余能量为 31 - 2 = 29 。\n - 完成第 3 个任务,剩余能量为 29 - 10 = 19 。\n - 完成第 4 个任务,剩余能量为 19 - 10 = 9 。\n - 完成第 5 个任务,剩余能量为 9 - 8 = 1 。</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><b>输入:</b>tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n<b>输出:</b>27\n<strong>解释:</strong>\n一开始有 27 能量,我们按照如下顺序完成任务:\n - 完成第 5 个任务,剩余能量为 27 - 5 = 22 。\n - 完成第 2 个任务,剩余能量为 22 - 2 = 20 。\n - 完成第 3 个任务,剩余能量为 20 - 3 = 17 。\n - 完成第 1 个任务,剩余能量为 17 - 1 = 16 。\n - 完成第 4 个任务,剩余能量为 16 - 4 = 12 。\n - 完成第 6 个任务,剩余能量为 12 - 6 = 6 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= actual<sub>i</sub> &lt;= minimum<sub>i</sub> &lt;= 10<sup>4</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 75,