1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-05 15:31:43 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -6,13 +6,13 @@
"boundTopicId": null,
"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] &gt; 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] &gt; 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>&nbsp;</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&#39;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&#39;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>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= rains.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>0 &lt;= rains[i] &lt;= 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] &gt; 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] &gt; 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>&nbsp;</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&#39;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&#39;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>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= rains.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>0 &lt;= rains[i] &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 938,
"dislikes": 188,
"likes": 986,
"dislikes": 198,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "[1,2,3,4]\n[1,2,0,0,2,1]\n[1,2,0,1,2]",
@@ -161,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"22.5K\", \"totalSubmission\": \"89.1K\", \"totalAcceptedRaw\": 22545, \"totalSubmissionRaw\": 89144, \"acRate\": \"25.3%\"}",
"stats": "{\"totalAccepted\": \"23.2K\", \"totalSubmission\": \"91.3K\", \"totalAcceptedRaw\": 23160, \"totalSubmissionRaw\": 91325, \"acRate\": \"25.4%\"}",
"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.",