1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 05:26:46 +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

@@ -12,7 +12,7 @@
"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",
"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."
],