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:
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>有一棵根节点为 <code>0</code>&nbsp;的 <strong>家族树</strong>&nbsp;,总共包含 <code>n</code>&nbsp;个节点,节点编号为 <code>0</code>&nbsp;到 <code>n - 1</code>&nbsp;。给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组 <code>parents</code>&nbsp;,其中&nbsp;<code>parents[i]</code>&nbsp;是节点 <code>i</code>&nbsp;的父节点。由于节点 <code>0</code>&nbsp;是 <strong>根</strong>&nbsp;,所以&nbsp;<code>parents[0] == -1</code>&nbsp;。</p>\n\n<p>总共有&nbsp;<code>10<sup>5</sup></code>&nbsp;个基因值,每个基因值都用 <strong>闭区间</strong>&nbsp;<code>[1, 10<sup>5</sup>]</code>&nbsp;中的一个整数表示。给你一个下标从&nbsp;<strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code>&nbsp;,其中&nbsp;<code>nums[i]</code>&nbsp;是节点 <code>i</code>&nbsp;的基因值,且基因值 <strong>互不相同</strong>&nbsp;。</p>\n\n<p>请你返回一个数组<em>&nbsp;</em><code>ans</code>&nbsp;,长度为&nbsp;<code>n</code>&nbsp;,其中&nbsp;<code>ans[i]</code>&nbsp;是以节点&nbsp;<code>i</code>&nbsp;为根的子树内 <b>缺失</b>&nbsp;的&nbsp;<strong>最小</strong>&nbsp;基因值。</p>\n\n<p>节点 <code>x</code>&nbsp;为根的 <strong>子树&nbsp;</strong>包含节点 <code>x</code>&nbsp;和它所有的 <strong>后代</strong>&nbsp;节点。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/08/23/case-1.png\" style=\"width: 204px; height: 167px;\"></p>\n\n<pre><b>输入:</b>parents = [-1,0,0,2], nums = [1,2,3,4]\n<b>输出:</b>[5,1,1,1]\n<b>解释:</b>每个子树答案计算结果如下:\n- 0子树包含节点 [0,1,2,3] ,基因值分别为 [1,2,3,4] 。5 是缺失的最小基因值。\n- 1子树只包含节点 1 ,基因值为 2 。1 是缺失的最小基因值。\n- 2子树包含节点 [2,3] ,基因值分别为 [3,4] 。1 是缺失的最小基因值。\n- 3子树只包含节点 3 ,基因值为 4 。1是缺失的最小基因值。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/08/23/case-2.png\" style=\"width: 247px; height: 168px;\"></p>\n\n<pre><b>输入:</b>parents = [-1,0,1,0,3,3], nums = [5,4,6,2,1,3]\n<b>输出:</b>[7,1,1,4,2,1]\n<b>解释:</b>每个子树答案计算结果如下:\n- 0子树内包含节点 [0,1,2,3,4,5] ,基因值分别为 [5,4,6,2,1,3] 。7 是缺失的最小基因值。\n- 1子树内包含节点 [1,2] ,基因值分别为 [4,6] 。 1 是缺失的最小基因值。\n- 2子树内只包含节点 2 ,基因值为 6 。1 是缺失的最小基因值。\n- 3子树内包含节点 [3,4,5] ,基因值分别为 [2,1,3] 。4 是缺失的最小基因值。\n- 4子树内只包含节点 4 ,基因值为 1 。2 是缺失的最小基因值。\n- 5子树内只包含节点 5 ,基因值为 3 。1 是缺失的最小基因值。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><b>输入:</b>parents = [-1,2,3,0,2,4,1], nums = [2,3,4,5,6,7,8]\n<b>输出:</b>[1,1,1,1,1,1,1]\n<b>解释:</b>所有子树都缺失基因值 1 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == parents.length == nums.length</code></li>\n\t<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>\n\t<li>对于&nbsp;<code>i != 0</code>&nbsp;,满足&nbsp;<code>0 &lt;= parents[i] &lt;= n - 1</code></li>\n\t<li><code>parents[0] == -1</code></li>\n\t<li><code>parents</code>&nbsp;表示一棵合法的树。</li>\n\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>\n\t<li><code>nums[i]</code>&nbsp;互不相同。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 29,
"likes": 30,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"2.2K\", \"totalSubmission\": \"5.5K\", \"totalAcceptedRaw\": 2215, \"totalSubmissionRaw\": 5494, \"acRate\": \"40.3%\"}",
"stats": "{\"totalAccepted\": \"2.3K\", \"totalSubmission\": \"5.6K\", \"totalAcceptedRaw\": 2273, \"totalSubmissionRaw\": 5604, \"acRate\": \"40.6%\"}",
"hints": [
"If the subtree doesn't contain 1, then the missing value will always be 1.",
"What data structure allows us to dynamically update the values that are currently not present?"