mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 05:26:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给定一个表 <code>tree</code>,<strong>id</strong> 是树节点的编号, <strong>p_id</strong> 是它父节点的 <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> </p>\n\n<p>写一个查询语句,输出所有节点的编号和节点的类型,并将结果按照节点编号排序。上面样例的结果为:</p>\n\n<p> </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> </p>\n\n<p><strong>解释</strong></p>\n\n<ul>\n\t<li>节点 '1' 是根节点,因为它的父节点是 NULL ,同时它有孩子节点 '2' 和 '3' 。</li>\n\t<li>节点 '2' 是内部节点,因为它有父节点 '1' ,也有孩子节点 '4' 和 '5' 。</li>\n\t<li>节点 '3', '4' 和 '5' 都是叶子节点,因为它们都有父节点同时没有孩子节点。</li>\n\t<li>样例中树的形态如下:\n\t<p> </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> </p>\n\t</li>\n</ul>\n\n<p><strong>注意</strong></p>\n\n<p>如果树中只有一个节点,你只需要输出它的根属性。</p>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 55,
|
||||
"likes": 66,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -47,7 +47,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"10.2K\", \"totalSubmission\": \"16.4K\", \"totalAcceptedRaw\": 10245, \"totalSubmissionRaw\": 16449, \"acRate\": \"62.3%\"}",
|
||||
"stats": "{\"totalAccepted\": \"14.3K\", \"totalSubmission\": \"22.6K\", \"totalAcceptedRaw\": 14276, \"totalSubmissionRaw\": 22554, \"acRate\": \"63.3%\"}",
|
||||
"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."
|
||||
],
|
||||
|
Reference in New Issue
Block a user