1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 15:01:40 +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><strong>完全二叉树</strong> 是每一层(除最后一层外)都是完全填充(即,节点数达到最大)的,并且所有的节点都尽可能地集中在左侧。</p>\n\n<p>设计一种算法,将一个新节点插入到一个完整的二叉树中,并在插入后保持其完整。</p>\n\n<p>实现 <code>CBTInserter</code> 类:</p>\n\n<ul>\n\t<li><code>CBTInserter(TreeNode root)</code>&nbsp;使用头节点为&nbsp;<code>root</code>&nbsp;的给定树初始化该数据结构;</li>\n\t<li><code>CBTInserter.insert(int v)</code>&nbsp; 向树中插入一个值为&nbsp;<code>Node.val == val</code>的新节点&nbsp;<code>TreeNode</code>。使树保持完全二叉树的状态,<strong>并返回插入节点</strong>&nbsp;<code>TreeNode</code>&nbsp;<strong>的父节点的值</strong></li>\n\t<li><code>CBTInserter.get_root()</code> 将返回树的头节点。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<ol>\n</ol>\n\n<p><strong>示例 1</strong></p>\n\n<p><img src=\"https://assets.leetcode.com/uploads/2021/08/03/lc-treeinsert.jpg\" style=\"height: 143px; width: 500px;\" /></p>\n\n<pre>\n<strong>输入</strong>\n[\"CBTInserter\", \"insert\", \"insert\", \"get_root\"]\n[[[1, 2]], [3], [4], []]\n<strong>输出</strong>\n[null, 1, 2, [1, 2, 3, 4]]\n\n<strong>解释</strong>\nCBTInserter cBTInserter = new CBTInserter([1, 2]);\ncBTInserter.insert(3); // 返回 1\ncBTInserter.insert(4); // 返回 2\ncBTInserter.get_root(); // 返回 [1, 2, 3, 4]</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li>树中节点数量范围为&nbsp;<code>[1, 1000]</code>&nbsp;</li>\n\t<li><code>0 &lt;= Node.val &lt;= 5000</code></li>\n\t<li><code>root</code>&nbsp;是完全二叉树</li>\n\t<li><code>0 &lt;= val &lt;= 5000</code>&nbsp;</li>\n\t<li>每个测试用例最多调用&nbsp;<code>insert</code>&nbsp;和&nbsp;<code>get_root</code>&nbsp;操作&nbsp;<code>10<sup>4</sup></code>&nbsp;次</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 64,
"likes": 65,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -155,11 +155,11 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"7.2K\", \"totalSubmission\": \"11K\", \"totalAcceptedRaw\": 7213, \"totalSubmissionRaw\": 11017, \"acRate\": \"65.5%\"}",
"stats": "{\"totalAccepted\": \"7.6K\", \"totalSubmission\": \"11.5K\", \"totalAcceptedRaw\": 7574, \"totalSubmissionRaw\": 11493, \"acRate\": \"65.9%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "[\"CBTInserter\",\"insert\",\"insert\",\"get_root\"]\n[[[1,2]],[3],[4],[]]",
"sampleTestCase": "[\"CBTInserter\",\"insert\",\"get_root\"]\n[[[1]],[2],[]]",
"metaData": "{\n \"classname\": \"CBTInserter\",\n \"maxbytesperline\": 200000,\n \"constructor\": {\n \"params\": [\n {\n \"name\": \"root\",\n \"type\": \"TreeNode\"\n }\n ]\n },\n \"methods\": [\n {\n \"name\": \"insert\",\n \"params\": [\n {\n \"name\": \"val\",\n \"type\": \"integer\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n }\n },\n {\n \"name\": \"get_root\",\n \"params\": [],\n \"return\": {\n \"type\": \"TreeNode\"\n }\n }\n ],\n \"systemdesign\": true,\n \"params\": [\n {\n \"name\": \"inputs\",\n \"type\": \"integer[]\"\n },\n {\n \"name\": \"inputs\",\n \"type\": \"integer[]\"\n }\n ],\n \"return\": {\n \"type\": \"list<String>\",\n \"dealloc\": true\n }\n}",
"judgerAvailable": true,
"judgeType": "large",