1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-08 00:41:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

存量题库数据更新

This commit is contained in:
2023-12-09 18:42:21 +08:00
parent a788808cd7
commit c198538f10
10843 changed files with 288489 additions and 248355 deletions

View File

@@ -7,17 +7,17 @@
"boundTopicId": 2637,
"title": "Tree Node",
"titleSlug": "tree-node",
"content": "<p>Table: <code>Tree</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| p_id | int |\n+-------------+------+\nid is the primary key column for this table.\nEach row of this table contains information about the id of a node and the id of its parent node in a tree.\nThe given structure is always a valid tree.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Each node in the tree can be one of three types:</p>\n\n<ul>\n\t<li><strong>&quot;Leaf&quot;</strong>: if the node is a leaf node.</li>\n\t<li><strong>&quot;Root&quot;</strong>: if the node is the root of the tree.</li>\n\t<li><strong>&quot;Inner&quot;</strong>: If the node is neither a leaf node nor a root node.</li>\n</ul>\n\n<p>Write an SQL query to report the type of each node in the tree.</p>\n\n<p>Return the result table <strong>ordered</strong> by <code>id</code> <strong>in ascending order</strong>.</p>\n\n<p>The query result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/22/tree1.jpg\" style=\"width: 304px; height: 224px;\" />\n<pre>\n<strong>Input:</strong> \nTree table:\n+----+------+\n| id | p_id |\n+----+------+\n| 1 | null |\n| 2 | 1 |\n| 3 | 1 |\n| 4 | 2 |\n| 5 | 2 |\n+----+------+\n<strong>Output:</strong> \n+----+-------+\n| id | type |\n+----+-------+\n| 1 | Root |\n| 2 | Inner |\n| 3 | Leaf |\n| 4 | Leaf |\n| 5 | Leaf |\n+----+-------+\n<strong>Explanation:</strong> \nNode 1 is the root node because its parent node is null and it has child nodes 2 and 3.\nNode 2 is an inner node because it has parent node 1 and child node 4 and 5.\nNodes 3, 4, and 5 are leaf nodes because they have parent nodes and they do not have child nodes.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/22/tree2.jpg\" style=\"width: 64px; height: 65px;\" />\n<pre>\n<strong>Input:</strong> \nTree table:\n+----+------+\n| id | p_id |\n+----+------+\n| 1 | null |\n+----+------+\n<strong>Output:</strong> \n+----+-------+\n| id | type |\n+----+-------+\n| 1 | Root |\n+----+-------+\n<strong>Explanation:</strong> If there is only one node on the tree, you only need to output its root attributes.\n</pre>\n",
"content": "<p>Table: <code>Tree</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| p_id | int |\n+-------------+------+\nid is the column with unique values for this table.\nEach row of this table contains information about the id of a node and the id of its parent node in a tree.\nThe given structure is always a valid tree.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Each node in the tree can be one of three types:</p>\n\n<ul>\n\t<li><strong>&quot;Leaf&quot;</strong>: if the node is a leaf node.</li>\n\t<li><strong>&quot;Root&quot;</strong>: if the node is the root of the tree.</li>\n\t<li><strong>&quot;Inner&quot;</strong>: If the node is neither a leaf node nor a root node.</li>\n</ul>\n\n<p>Write a solution to report the type of each node in the tree.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/22/tree1.jpg\" style=\"width: 304px; height: 224px;\" />\n<pre>\n<strong>Input:</strong> \nTree table:\n+----+------+\n| id | p_id |\n+----+------+\n| 1 | null |\n| 2 | 1 |\n| 3 | 1 |\n| 4 | 2 |\n| 5 | 2 |\n+----+------+\n<strong>Output:</strong> \n+----+-------+\n| id | type |\n+----+-------+\n| 1 | Root |\n| 2 | Inner |\n| 3 | Leaf |\n| 4 | Leaf |\n| 5 | Leaf |\n+----+-------+\n<strong>Explanation:</strong> \nNode 1 is the root node because its parent node is null and it has child nodes 2 and 3.\nNode 2 is an inner node because it has parent node 1 and child node 4 and 5.\nNodes 3, 4, and 5 are leaf nodes because they have parent nodes and they do not have child nodes.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/22/tree2.jpg\" style=\"width: 64px; height: 65px;\" />\n<pre>\n<strong>Input:</strong> \nTree table:\n+----+------+\n| id | p_id |\n+----+------+\n| 1 | null |\n+----+------+\n<strong>Output:</strong> \n+----+-------+\n| id | type |\n+----+-------+\n| 1 | Root |\n+----+-------+\n<strong>Explanation:</strong> If there is only one node on the tree, you only need to output its root attributes.\n</pre>\n",
"translatedTitle": "树节点",
"translatedContent": "<p>给定一个表&nbsp;<code>tree</code><strong>id</strong> 是树节点的编号,&nbsp;<strong>p_id</strong>&nbsp;是它父节点的&nbsp;<strong>id 。</strong></p>\n\n<pre>+----+------+\n| id | p_id |\n+----+------+\n| 1 | null |\n| 2 | 1 |\n| 3 | 1 |\n| 4 | 2 |\n| 5 | 2 |\n+----+------+</pre>\n\n<p>树中每个节点属于以下三种类型之一:</p>\n\n<ul>\n\t<li>叶子:如果这个节点没有任何孩子节点。</li>\n\t<li>根:如果这个节点是整棵树的根,即没有父节点。</li>\n\t<li>内部节点:如果这个节点既不是叶子节点也不是根节点。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p>写一个查询语句,输出所有节点的编号和节点的类型,并将结果按照节点编号排序。上面样例的结果为:</p>\n\n<p>&nbsp;</p>\n\n<pre>+----+------+\n| id | Type |\n+----+------+\n| 1 | Root |\n| 2 | Inner|\n| 3 | Leaf |\n| 4 | Leaf |\n| 5 | Leaf |\n+----+------+\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>解释</strong></p>\n\n<ul>\n\t<li>节点 &#39;1&#39; 是根节点,因为它的父节点是 NULL ,同时它有子节点 &#39;2&#39; 和 &#39;3&#39; 。</li>\n\t<li>节点 &#39;2&#39; 是内部节点,因为它有父节点 &#39;1&#39; ,也有孩子节点 &#39;4&#39; 和 &#39;5&#39; 。</li>\n\t<li>节点 &#39;3&#39;, &#39;4&#39; 和 &#39;5&#39; 都是叶子节点,因为它们有父节点同时没有子节点。</li>\n\t<li>样例中树的形态如下:\n\t<p>&nbsp;</p>\n\n\t<pre>\t\t\t 1\n\t\t\t/ \\\n 2 3\n / \\\n 4 5\n</pre>\n\n\t<p>&nbsp;</p>\n\t</li>\n</ul>\n\n<p><strong>注意</strong></p>\n\n<p>如果树中只有一个节点,只需要输出它的根属性。</p>\n",
"translatedContent": "<p>表:<code>Tree</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| p_id | int |\n+-------------+------+\nid 是该表中具有唯一值的列。\n该表的每行包含树中节点的 id 及其父节点的 id 信息。\n给定的结构总是一个有效的树。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>树中每个节点可以是以下三种类型之一:</p>\n\n<ul>\n\t<li><strong>\"Leaf\"</strong>:节点是叶子节点。</li>\n\t<li><strong>\"Root\"</strong>节点是树的根节点。</li>\n\t<li><strong>\"lnner\"</strong>节点既不是叶子节点也不是根节点。</li>\n</ul>\n\n<p>编写一个解决方案来报告树中每个节点的类型。</p>\n\n<p>以 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/22/tree1.jpg\" style=\"width: 304px; height: 224px;\" />\n<pre>\n<b>输入:</b>\nTree table:\n+----+------+\n| id | p_id |\n+----+------+\n| 1 | null |\n| 2 | 1 |\n| 3 | 1 |\n| 4 | 2 |\n| 5 | 2 |\n+----+------+\n<b>输出:</b>\n+----+-------+\n| id | type |\n+----+-------+\n| 1 | Root |\n| 2 | Inner |\n| 3 | Leaf |\n| 4 | Leaf |\n| 5 | Leaf |\n+----+-------+\n<b>解释</b>\n节点 1 是根节点,因为它的父节点为空,并且它有子节点 2 和 3。\n节点 2 是一个内部节点,因为它有父节点 1 和子节点 4 和 5。\n节点 3、4 和 5 是叶子节点,因为它们有父节点没有子节点。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/22/tree2.jpg\" style=\"width: 64px; height: 65px;\" />\n<pre>\n<b>输入:</b>\nTree table:\n+----+------+\n| id | p_id |\n+----+------+\n| 1 | null |\n+----+------+\n<b>输出:</b>\n+----+-------+\n| id | type |\n+----+-------+\n| 1 | Root |\n+----+-------+\n<b>解释:</b>如果树中只有一个节点,只需要输出根属性。\n</pre>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 66,
"likes": 209,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}",
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [
{
"name": "Database",
@@ -45,16 +45,28 @@
"langSlug": "oraclesql",
"code": "/* Write your PL/SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef tree_node(tree: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"14.3K\", \"totalSubmission\": \"22.6K\", \"totalAcceptedRaw\": 14276, \"totalSubmissionRaw\": 22554, \"acRate\": \"63.3%\"}",
"stats": "{\"totalAccepted\": \"62.1K\", \"totalSubmission\": \"100.8K\", \"totalAcceptedRaw\": 62123, \"totalSubmissionRaw\": 100846, \"acRate\": \"61.6%\"}",
"hints": [
"You can judge the node type by querying whether the node's id shows up in p_id column and whether the node's p_id is null."
],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\": {\"Tree\": [\"id\", \"p_id\"]}, \"rows\": {\"Tree\": [[1,null],[2,1],[3,1],[4,2],[5,2]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Tree (id int, p_id int)\"\n ],\n \"mssql\": [\n \"Create table Tree (id int, p_id int)\"\n ],\n \"oraclesql\": [\n \"Create table Tree (id int, p_id int)\"\n ],\n \"database\": true\n}",
"sampleTestCase": "{\"headers\":{\"Tree\":[\"id\",\"p_id\"]},\"rows\":{\"Tree\":[[1,null],[2,1],[3,1],[4,2],[5,2]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Tree (id int, p_id int)\"],\"mssql\":[\"Create table Tree (id int, p_id int)\"],\"oraclesql\":[\"Create table Tree (id int, p_id int)\"],\"database\":true,\"name\":\"tree_node\",\"pythondata\":[\"Tree = pd.DataFrame([], columns=['id', 'p_id']).astype({'id':'Int64', 'p_id':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Tree (id int, p_id int)\"],\"database_schema\":{\"Tree\":{\"id\":\"INT\",\"p_id\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
@@ -67,7 +79,7 @@
"insert into Tree (id, p_id) values ('5', '2')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
@@ -75,7 +87,7 @@
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\": {\"Tree\": [\"id\", \"p_id\"]}, \"rows\": {\"Tree\": [[1,null],[2,1],[3,1],[4,2],[5,2]]}}\n{\"headers\": {\"Tree\": [\"id\", \"p_id\"]}, \"rows\": {\"Tree\": [[1,null]]}}",
"exampleTestcases": "{\"headers\":{\"Tree\":[\"id\",\"p_id\"]},\"rows\":{\"Tree\":[[1,null],[2,1],[3,1],[4,2],[5,2]]}}\n{\"headers\":{\"Tree\":[\"id\",\"p_id\"]},\"rows\":{\"Tree\":[[1,null]]}}",
"__typename": "QuestionNode"
}
}