mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-02 22:13:28 +08:00
update
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
"boundTopicId": 292721,
|
||||
"title": "Avoid Flood in The City",
|
||||
"titleSlug": "avoid-flood-in-the-city",
|
||||
"content": "<p>Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the <code>nth</code> lake, the <code>nth</code> lake becomes full of water. If it rains over a lake which is <strong>full of water</strong>, there will be a <strong>flood</strong>. Your goal is to avoid the flood in any lake.</p>\n\n<p>Given an integer array <code>rains</code> where:</p>\n\n<ul>\n\t<li><code>rains[i] > 0</code> means there will be rains over the <code>rains[i]</code> lake.</li>\n\t<li><code>rains[i] == 0</code> means there are no rains this day and you can choose <strong>one lake</strong> this day and <strong>dry it</strong>.</li>\n</ul>\n\n<p>Return <em>an array <code>ans</code></em> where:</p>\n\n<ul>\n\t<li><code>ans.length == rains.length</code></li>\n\t<li><code>ans[i] == -1</code> if <code>rains[i] > 0</code>.</li>\n\t<li><code>ans[i]</code> is the lake you choose to dry in the <code>ith</code> day if <code>rains[i] == 0</code>.</li>\n</ul>\n\n<p>If there are multiple valid answers return <strong>any</strong> of them. If it is impossible to avoid flood return <strong>an empty array</strong>.</p>\n\n<p>Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes. (see example 4)</p>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> rains = [1,2,3,4]\n<strong>Output:</strong> [-1,-1,-1,-1]\n<strong>Explanation:</strong> After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day full lakes are [1,2,3]\nAfter the fourth day full lakes are [1,2,3,4]\nThere's no day to dry any lake and there is no flood in any lake.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> rains = [1,2,0,0,2,1]\n<strong>Output:</strong> [-1,-1,2,1,-1,-1]\n<strong>Explanation:</strong> After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day, we dry lake 2. Full lakes are [1]\nAfter the fourth day, we dry lake 1. There is no full lakes.\nAfter the fifth day, full lakes are [2].\nAfter the sixth day, full lakes are [1,2].\nIt is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> rains = [1,2,0,1,2]\n<strong>Output:</strong> []\n<strong>Explanation:</strong> After the second day, full lakes are [1,2]. We have to dry one lake in the third day.\nAfter that, it will rain over lakes [1,2]. It's easy to prove that no matter which lake you choose to dry in the 3rd day, the other one will flood.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= rains.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= rains[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the <code>nth</code> lake, the <code>nth</code> lake becomes full of water. If it rains over a lake that is <strong>full of water</strong>, there will be a <strong>flood</strong>. Your goal is to avoid floods in any lake.</p>\n\n<p>Given an integer array <code>rains</code> where:</p>\n\n<ul>\n\t<li><code>rains[i] > 0</code> means there will be rains over the <code>rains[i]</code> lake.</li>\n\t<li><code>rains[i] == 0</code> means there are no rains this day and you can choose <strong>one lake</strong> this day and <strong>dry it</strong>.</li>\n</ul>\n\n<p>Return <em>an array <code>ans</code></em> where:</p>\n\n<ul>\n\t<li><code>ans.length == rains.length</code></li>\n\t<li><code>ans[i] == -1</code> if <code>rains[i] > 0</code>.</li>\n\t<li><code>ans[i]</code> is the lake you choose to dry in the <code>ith</code> day if <code>rains[i] == 0</code>.</li>\n</ul>\n\n<p>If there are multiple valid answers return <strong>any</strong> of them. If it is impossible to avoid flood return <strong>an empty array</strong>.</p>\n\n<p>Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes.</p>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> rains = [1,2,3,4]\n<strong>Output:</strong> [-1,-1,-1,-1]\n<strong>Explanation:</strong> After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day full lakes are [1,2,3]\nAfter the fourth day full lakes are [1,2,3,4]\nThere's no day to dry any lake and there is no flood in any lake.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> rains = [1,2,0,0,2,1]\n<strong>Output:</strong> [-1,-1,2,1,-1,-1]\n<strong>Explanation:</strong> After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day, we dry lake 2. Full lakes are [1]\nAfter the fourth day, we dry lake 1. There is no full lakes.\nAfter the fifth day, full lakes are [2].\nAfter the sixth day, full lakes are [1,2].\nIt is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> rains = [1,2,0,1,2]\n<strong>Output:</strong> []\n<strong>Explanation:</strong> After the second day, full lakes are [1,2]. We have to dry one lake in the third day.\nAfter that, it will rain over lakes [1,2]. It's easy to prove that no matter which lake you choose to dry in the 3rd day, the other one will flood.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= rains.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= rains[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": "避免洪水泛滥",
|
||||
"translatedContent": "<p>你的国家有无数个湖泊,所有湖泊一开始都是空的。当第 <code>n</code> 个湖泊下雨的时候,那么它就会装满水。如果第 <code>n</code> 个湖泊是 <strong>满的 </strong>,这个湖泊会发生 <strong>洪水</strong> 。你的目标是避免任意一个湖泊发生洪水。</p>\n\n<p>给你一个整数数组 <code>rains</code> ,其中:</p>\n\n<ul>\n\t<li><code>rains[i] > 0</code> 表示第 <code>i</code> 天时,第 <code>rains[i]</code> 个湖泊会下雨。</li>\n\t<li><code>rains[i] == 0</code> 表示第 <code>i</code> 天没有湖泊会下雨,你可以选择 <strong>一个</strong> 湖泊并 <strong>抽干</strong> 这个湖泊的水。</li>\n</ul>\n\n<p>请返回一个数组<em> </em><code>ans</code> ,满足:</p>\n\n<ul>\n\t<li><code>ans.length == rains.length</code></li>\n\t<li>如果 <code>rains[i] > 0</code> ,那么<code>ans[i] == -1</code> 。</li>\n\t<li>如果 <code>rains[i] == 0</code> ,<code>ans[i]</code> 是你第 <code>i</code> 天选择抽干的湖泊。</li>\n</ul>\n\n<p>如果有多种可行解,请返回它们中的 <strong>任意一个</strong> 。如果没办法阻止洪水,请返回一个 <strong>空的数组</strong> 。</p>\n\n<p>请注意,如果你选择抽干一个装满水的湖泊,它会变成一个空的湖泊。但如果你选择抽干一个空的湖泊,那么将无事发生(详情请看示例 4)。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>rains = [1,2,3,4]\n<strong>输出:</strong>[-1,-1,-1,-1]\n<strong>解释:</strong>第一天后,装满水的湖泊包括 [1]\n第二天后,装满水的湖泊包括 [1,2]\n第三天后,装满水的湖泊包括 [1,2,3]\n第四天后,装满水的湖泊包括 [1,2,3,4]\n没有哪一天你可以抽干任何湖泊的水,也没有湖泊会发生洪水。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>rains = [1,2,0,0,2,1]\n<strong>输出:</strong>[-1,-1,2,1,-1,-1]\n<strong>解释:</strong>第一天后,装满水的湖泊包括 [1]\n第二天后,装满水的湖泊包括 [1,2]\n第三天后,我们抽干湖泊 2 。所以剩下装满水的湖泊包括 [1]\n第四天后,我们抽干湖泊 1 。所以暂时没有装满水的湖泊了。\n第五天后,装满水的湖泊包括 [2]。\n第六天后,装满水的湖泊包括 [1,2]。\n可以看出,这个方案下不会有洪水发生。同时, [-1,-1,1,2,-1,-1] 也是另一个可行的没有洪水的方案。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>rains = [1,2,0,1,2]\n<strong>输出:</strong>[]\n<strong>解释:</strong>第二天后,装满水的湖泊包括 [1,2]。我们可以在第三天抽干一个湖泊的水。\n但第三天后,湖泊 1 和 2 都会再次下雨,所以不管我们第三天抽干哪个湖泊的水,另一个湖泊都会发生洪水。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= rains.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= rains[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 87,
|
||||
"likes": 89,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -161,7 +161,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"8.7K\", \"totalSubmission\": \"35.3K\", \"totalAcceptedRaw\": 8744, \"totalSubmissionRaw\": 35344, \"acRate\": \"24.7%\"}",
|
||||
"stats": "{\"totalAccepted\": \"9K\", \"totalSubmission\": \"36.3K\", \"totalAcceptedRaw\": 9009, \"totalSubmissionRaw\": 36258, \"acRate\": \"24.8%\"}",
|
||||
"hints": [
|
||||
"Keep An array of the last day there was rains over each city.",
|
||||
"Keep an array of the days you can dry a lake when you face one.",
|
||||
|
Reference in New Issue
Block a user