mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-10 01:41:41 +08:00
移除零宽空格
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
"titleSlug": "earliest-second-to-mark-indices-i",
|
||||
"content": "<p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p>\n\n<p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>\n\n<p>In each second, <code>s</code>, in order from <code>1</code> to <code>m</code> (<strong>inclusive</strong>), you can perform <strong>one</strong> of the following operations:</p>\n\n<ul>\n\t<li>Choose an index <code>i</code> in the range <code>[1, n]</code> and <strong>decrement</strong> <code>nums[i]</code> by <code>1</code>.</li>\n\t<li>If <code>nums[changeIndices[s]]</code> is <strong>equal</strong> to <code>0</code>, <strong>mark</strong> the index <code>changeIndices[s]</code>.</li>\n\t<li>Do nothing.</li>\n</ul>\n\n<p>Return <em>an integer denoting the <strong>earliest second</strong> in the range </em><code>[1, m]</code><em> when <strong>all</strong> indices in </em><code>nums</code><em> can be marked by choosing operations optimally, or </em><code>-1</code><em> if it is impossible.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1]\n<strong>Output:</strong> 8\n<strong>Explanation:</strong> In this example, we have 8 seconds. The following operations can be performed to mark all indices:\nSecond 1: Choose index 1 and decrement nums[1] by one. nums becomes [1,2,0].\nSecond 2: Choose index 1 and decrement nums[1] by one. nums becomes [0,2,0].\nSecond 3: Choose index 2 and decrement nums[2] by one. nums becomes [0,1,0].\nSecond 4: Choose index 2 and decrement nums[2] by one. nums becomes [0,0,0].\nSecond 5: Mark the index changeIndices[5], which is marking index 3, since nums[3] is equal to 0.\nSecond 6: Mark the index changeIndices[6], which is marking index 2, since nums[2] is equal to 0.\nSecond 7: Do nothing.\nSecond 8: Mark the index changeIndices[8], which is marking index 1, since nums[1] is equal to 0.\nNow all indices have been marked.\nIt can be shown that it is not possible to mark all indices earlier than the 8th second.\nHence, the answer is 8.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3], changeIndices = [1,1,1,2,1,1,1]\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> In this example, we have 7 seconds. The following operations can be performed to mark all indices:\nSecond 1: Choose index 2 and decrement nums[2] by one. nums becomes [1,2].\nSecond 2: Choose index 2 and decrement nums[2] by one. nums becomes [1,1].\nSecond 3: Choose index 2 and decrement nums[2] by one. nums becomes [1,0].\nSecond 4: Mark the index changeIndices[4], which is marking index 2, since nums[2] is equal to 0.\nSecond 5: Choose index 1 and decrement nums[1] by one. nums becomes [0,0].\nSecond 6: Mark the index changeIndices[6], which is marking index 1, since nums[1] is equal to 0.\nNow all indices have been marked.\nIt can be shown that it is not possible to mark all indices earlier than the 6th second.\nHence, the answer is 6.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1], changeIndices = [2,2,2]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> In this example, it is impossible to mark all indices because index 1 isn't in changeIndices.\nHence, the answer is -1.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= n == nums.length <= 2000</code></li>\n\t<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= m == changeIndices.length <= 2000</code></li>\n\t<li><code>1 <= changeIndices[i] <= n</code></li>\n</ul>\n",
|
||||
"translatedTitle": "标记所有下标的最早秒数 I",
|
||||
"translatedContent": "<p>给你两个下标从 <strong>1</strong> 开始的整数数组 <code>nums</code> 和 <code>changeIndices</code> ,数组的长度分别为 <code>n</code> 和 <code>m</code> 。</p>\n\n<p>一开始,<code>nums</code> 中所有下标都是未标记的,你的任务是标记 <code>nums</code> 中 <strong>所有</strong> 下标。</p>\n\n<p>从第 <code>1</code> 秒到第 <code>m</code> 秒(<b>包括 </b>第 <code>m</code> 秒),对于每一秒 <code>s</code> ,你可以执行以下操作 <strong>之一</strong> :</p>\n\n<ul>\n\t<li>选择范围 <code>[1, n]</code> 中的一个下标 <code>i</code> ,并且将 <code>nums[i]</code> <strong>减少</strong> <code>1</code> 。</li>\n\t<li>如果 <code>nums[changeIndices[s]]</code> <strong>等于</strong> <code>0</code> ,<strong>标记</strong> 下标 <code>changeIndices[s]</code> 。</li>\n\t<li>什么也不做。</li>\n</ul>\n\n<p>请你返回范围 <code>[1, m]</code> 中的一个整数,表示最优操作下,标记 <code>nums</code> 中 <strong>所有</strong> 下标的 <strong>最早秒数</strong> ,如果无法标记所有下标,返回 <code>-1</code> 。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1]\n<b>输出:</b>8\n<b>解释:</b>这个例子中,我们总共有 8 秒。按照以下操作标记所有下标:\n第 1 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [1,2,0] 。\n第 2 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [0,2,0] 。\n第 3 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [0,1,0] 。\n第 4 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [0,0,0] 。\n第 5 秒,标记 changeIndices[5] ,也就是标记下标 3 ,因为 nums[3] 等于 0 。\n第 6 秒,标记 changeIndices[6] ,也就是标记下标 2 ,因为 nums[2] 等于 0 。\n第 7 秒,什么也不做。\n第 8 秒,标记 changeIndices[8] ,也就是标记下标 1 ,因为 nums[1] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 8 秒标记所有下标。\n所以答案是 8 。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [1,3], changeIndices = [1,1,1,2,1,1,1]\n<b>输出:</b>6\n<b>解释:</b>这个例子中,我们总共有 7 秒。按照以下操作标记所有下标:\n第 1 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,2] 。\n第 2 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,1] 。\n第 3 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,0] 。\n第 4 秒:标记 changeIndices[4] ,也就是标记下标 2 ,因为 nums[2] 等于 0 。\n第 5 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [0,0] 。\n第 6 秒:标记 changeIndices[6] ,也就是标记下标 1 ,因为 nums[1] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 6 秒标记所有下标。\n所以答案是 6 。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1], changeIndices = [2,2,2]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> 这个例子中,无法标记所有下标,因为下标 1 不在 changeIndices 中。\n所以答案是 -1 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= n == nums.length <= 2000</code></li>\n\t<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= m == changeIndices.length <= 2000</code></li>\n\t<li><code>1 <= changeIndices[i] <= n</code></li>\n</ul>\n",
|
||||
"translatedContent": "<p>给你两个下标从 <strong>1</strong> 开始的整数数组 <code>nums</code> 和 <code>changeIndices</code> ,数组的长度分别为 <code>n</code> 和 <code>m</code> 。</p>\n\n<p>一开始,<code>nums</code> 中所有下标都是未标记的,你的任务是标记 <code>nums</code> 中 <strong>所有</strong> 下标。</p>\n\n<p>从第 <code>1</code> 秒到第 <code>m</code> 秒(<b>包括 </b>第 <code>m</code> 秒),对于每一秒 <code>s</code> ,你可以执行以下操作 <strong>之一</strong> :</p>\n\n<ul>\n\t<li>选择范围 <code>[1, n]</code> 中的一个下标 <code>i</code> ,并且将 <code>nums[i]</code> <strong>减少</strong> <code>1</code> 。</li>\n\t<li>如果 <code>nums[changeIndices[s]]</code> <strong>等于</strong> <code>0</code> ,<strong>标记</strong> 下标 <code>changeIndices[s]</code> 。</li>\n\t<li>什么也不做。</li>\n</ul>\n\n<p>请你返回范围 <code>[1, m]</code> 中的一个整数,表示最优操作下,标记 <code>nums</code> 中 <strong>所有</strong> 下标的 <strong>最早秒数</strong> ,如果无法标记所有下标,返回 <code>-1</code> 。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [2,2,0], changeIndices = [2,2,2,2,3,2,2,1]\n<b>输出:</b>8\n<b>解释:</b>这个例子中,我们总共有 8 秒。按照以下操作标记所有下标:\n第 1 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [1,2,0] 。\n第 2 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [0,2,0] 。\n第 3 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [0,1,0] 。\n第 4 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [0,0,0] 。\n第 5 秒,标记 changeIndices[5] ,也就是标记下标 3 ,因为 nums[3] 等于 0 。\n第 6 秒,标记 changeIndices[6] ,也就是标记下标 2 ,因为 nums[2] 等于 0 。\n第 7 秒,什么也不做。\n第 8 秒,标记 changeIndices[8] ,也就是标记下标 1 ,因为 nums[1] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 8 秒标记所有下标。\n所以答案是 8 。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [1,3], changeIndices = [1,1,1,2,1,1,1]\n<b>输出:</b>6\n<b>解释:</b>这个例子中,我们总共有 7 秒。按照以下操作标记所有下标:\n第 1 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,2] 。\n第 2 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,1] 。\n第 3 秒:选择下标 2 ,将 nums[2] 减少 1 。nums 变为 [1,0] 。\n第 4 秒:标记 changeIndices[4] ,也就是标记下标 2 ,因为 nums[2] 等于 0 。\n第 5 秒:选择下标 1 ,将 nums[1] 减少 1 。nums 变为 [0,0] 。\n第 6 秒:标记 changeIndices[6] ,也就是标记下标 1 ,因为 nums[1] 等于 0 。\n现在所有下标已被标记。\n最早可以在第 6 秒标记所有下标。\n所以答案是 6 。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1], changeIndices = [2,2,2]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> 这个例子中,无法标记所有下标,因为下标 1 不在 changeIndices 中。\n所以答案是 -1 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= n == nums.length <= 2000</code></li>\n\t<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= m == changeIndices.length <= 2000</code></li>\n\t<li><code>1 <= changeIndices[i] <= n</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 28,
|
||||
|
Reference in New Issue
Block a user