mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-08 00:41:42 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>有一棵根节点为 <code>0</code> 的 <strong>家族树</strong> ,总共包含 <code>n</code> 个节点,节点编号为 <code>0</code> 到 <code>n - 1</code> 。给你一个下标从 <strong>0</strong> 开始的整数数组 <code>parents</code> ,其中 <code>parents[i]</code> 是节点 <code>i</code> 的父节点。由于节点 <code>0</code> 是 <strong>根</strong> ,所以 <code>parents[0] == -1</code> 。</p>\n\n<p>总共有 <code>10<sup>5</sup></code> 个基因值,每个基因值都用 <strong>闭区间</strong> <code>[1, 10<sup>5</sup>]</code> 中的一个整数表示。给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,其中 <code>nums[i]</code> 是节点 <code>i</code> 的基因值,且基因值 <strong>互不相同</strong> 。</p>\n\n<p>请你返回一个数组<em> </em><code>ans</code> ,长度为 <code>n</code> ,其中 <code>ans[i]</code> 是以节点 <code>i</code> 为根的子树内 <b>缺失</b> 的 <strong>最小</strong> 基因值。</p>\n\n<p>节点 <code>x</code> 为根的 <strong>子树 </strong>包含节点 <code>x</code> 和它所有的 <strong>后代</strong> 节点。</p>\n\n<p> </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> </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 <= n <= 10<sup>5</sup></code></li>\n\t<li>对于 <code>i != 0</code> ,满足 <code>0 <= parents[i] <= n - 1</code></li>\n\t<li><code>parents[0] == -1</code></li>\n\t<li><code>parents</code> 表示一棵合法的树。</li>\n\t<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>\n\t<li><code>nums[i]</code> 互不相同。</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?"
|
||||
|
Reference in New Issue
Block a user