mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-10 01:41:41 +08:00
update
This commit is contained in:
@@ -9,10 +9,10 @@
|
||||
"titleSlug": "find-eventual-safe-states",
|
||||
"content": "<p>There is a directed graph of <code>n</code> nodes with each node labeled from <code>0</code> to <code>n - 1</code>. The graph is represented by a <strong>0-indexed</strong> 2D integer array <code>graph</code> where <code>graph[i]</code> is an integer array of nodes adjacent to node <code>i</code>, meaning there is an edge from node <code>i</code> to each node in <code>graph[i]</code>.</p>\n\n<p>A node is a <strong>terminal node</strong> if there are no outgoing edges. A node is a <strong>safe node</strong> if every possible path starting from that node leads to a <strong>terminal node</strong>.</p>\n\n<p>Return <em>an array containing all the <strong>safe nodes</strong> of the graph</em>. The answer should be sorted in <strong>ascending</strong> order.</p>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n<img alt=\"Illustration of graph\" src=\"https://s3-lc-upload.s3.amazonaws.com/uploads/2018/03/17/picture1.png\" style=\"height: 171px; width: 600px;\" />\n<pre>\n<strong>Input:</strong> graph = [[1,2],[2,3],[5],[0],[5],[],[]]\n<strong>Output:</strong> [2,4,5,6]\n<strong>Explanation:</strong> The given graph is shown above.\nNodes 5 and 6 are terminal nodes as there are no outgoing edges from either of them.\nEvery path starting at nodes 2, 4, 5, and 6 all lead to either node 5 or 6.</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\n<strong>Output:</strong> [4]\n<strong>Explanation:</strong>\nOnly node 4 is a terminal node, and every path starting at node 4 leads to node 4.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == graph.length</code></li>\n\t<li><code>1 <= n <= 10<sup>4</sup></code></li>\n\t<li><code>0 <= graph[i].length <= n</code></li>\n\t<li><code>0 <= graph[i][j] <= n - 1</code></li>\n\t<li><code>graph[i]</code> is sorted in a strictly increasing order.</li>\n\t<li>The graph may contain self-loops.</li>\n\t<li>The number of edges in the graph will be in the range <code>[1, 4 * 10<sup>4</sup>]</code>.</li>\n</ul>\n",
|
||||
"translatedTitle": "找到最终的安全状态",
|
||||
"translatedContent": "<p>有一个有 <code>n</code> 个节点的有向图,节点按 <code>0</code> 到 <code>n - 1</code> 编号。图由一个 <strong>索引从 0 开始</strong> 的 2D 整数数组 <code>graph</code>表示, <code>graph[i]</code>是与节点 <code>i</code> 相邻的节点的整数数组,这意味着从节点 <code>i</code> 到 <code>graph[i]</code>中的每个节点都有一条边。</p>\n\n<p>如果一个节点没有连出的有向边,则它是 <strong>终端节点</strong> 。如果没有出边,则节点为终端节点。如果从该节点开始的所有可能路径都通向一个 <strong>终端节点</strong> ,则该节点为 <strong>安全节点</strong> 。</p>\n\n<p>返回一个由图中所有 <strong>安全节点</strong> 组成的数组作为答案。答案数组中的元素应当按 <strong>升序</strong> 排列。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"Illustration of graph\" src=\"https://s3-lc-upload.s3.amazonaws.com/uploads/2018/03/17/picture1.png\" /></p>\n\n<pre>\n<strong>输入:</strong>graph = [[1,2],[2,3],[5],[0],[5],[],[]]\n<strong>输出:</strong>[2,4,5,6]\n<strong>解释:</strong>示意图如上。\n节点5和节点6是终端节点,因为它们都没有出边。\n从节点2、4、5和6开始的所有路径都指向节点5或6。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\n<strong>输出:</strong>[4]\n<strong>解释:</strong>\n只有节点4是终端节点,从节点4开始的所有路径都通向节点4。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == graph.length</code></li>\n\t<li><code>1 <= n <= 10<sup>4</sup></code></li>\n\t<li><code>0 <= graph[i].length <= n</code></li>\n\t<li><code>graph[i]</code> 按严格递增顺序排列。</li>\n\t<li>图中可能包含自环。</li>\n\t<li>图中边的数目在范围 <code>[1, 4 * 10<sup>4</sup>]</code> 内。</li>\n</ul>\n",
|
||||
"translatedContent": "<p>有一个有 <code>n</code> 个节点的有向图,节点按 <code>0</code> 到 <code>n - 1</code> 编号。图由一个 <strong>索引从 0 开始</strong> 的 2D 整数数组 <code>graph</code>表示, <code>graph[i]</code>是与节点 <code>i</code> 相邻的节点的整数数组,这意味着从节点 <code>i</code> 到 <code>graph[i]</code>中的每个节点都有一条边。</p>\n\n<p>如果一个节点没有连出的有向边,则它是 <strong>终端节点</strong> 。如果没有出边,则节点为终端节点。如果从该节点开始的所有可能路径都通向 <strong>终端节点</strong> ,则该节点为 <strong>安全节点</strong> 。</p>\n\n<p>返回一个由图中所有 <strong>安全节点</strong> 组成的数组作为答案。答案数组中的元素应当按 <strong>升序</strong> 排列。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"Illustration of graph\" src=\"https://s3-lc-upload.s3.amazonaws.com/uploads/2018/03/17/picture1.png\" /></p>\n\n<pre>\n<strong>输入:</strong>graph = [[1,2],[2,3],[5],[0],[5],[],[]]\n<strong>输出:</strong>[2,4,5,6]\n<strong>解释:</strong>示意图如上。\n节点 5 和节点 6 是终端节点,因为它们都没有出边。\n从节点 2、4、5 和 6 开始的所有路径都指向节点 5 或 6 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\n<strong>输出:</strong>[4]\n<strong>解释:</strong>\n只有节点 4 是终端节点,从节点 4 开始的所有路径都通向节点 4 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == graph.length</code></li>\n\t<li><code>1 <= n <= 10<sup>4</sup></code></li>\n\t<li><code>0 <= graph[i].length <= n</code></li>\n\t<li><code>0 <= graph[i][j] <= n - 1</code></li>\n\t<li><code>graph[i]</code> 按严格递增顺序排列。</li>\n\t<li>图中可能包含自环。</li>\n\t<li>图中边的数目在范围 <code>[1, 4 * 10<sup>4</sup>]</code> 内。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 316,
|
||||
"likes": 320,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"34.8K\", \"totalSubmission\": \"59.9K\", \"totalAcceptedRaw\": 34787, \"totalSubmissionRaw\": 59923, \"acRate\": \"58.1%\"}",
|
||||
"stats": "{\"totalAccepted\": \"35.6K\", \"totalSubmission\": \"61.1K\", \"totalAcceptedRaw\": 35583, \"totalSubmissionRaw\": 61118, \"acRate\": \"58.2%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
|
Reference in New Issue
Block a user