1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 11:08:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/二叉树中所有距离为 K 的结点 [all-nodes-distance-k-in-binary-tree].html

40 lines
1.3 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>给定一个二叉树(具有根结点&nbsp;<code>root</code>&nbsp;一个目标结点&nbsp;<code>target</code>&nbsp;,和一个整数值 <code>k</code></p>
<p>返回到目标结点 <code>target</code> 距离为 <code>k</code> 的所有结点的值的列表。 答案可以以 <strong>任何顺序</strong> 返回。</p>
<p>&nbsp;</p>
<ol>
</ol>
<p><strong>示例 1</strong></p>
<p><img src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/06/28/sketch0.png" style="height: 429px; width: 500px;" /></p>
<pre>
<strong>输入:</strong>root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2
<strong>输出:</strong>[7,4,1]
<strong>解释:</strong>所求结点为与目标结点(值为 5距离为 2 的结点,值分别为 74以及 1
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong> root = [1], target = 1, k = 3
<strong>输出:</strong> []
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>节点数在&nbsp;<code>[1, 500]</code>&nbsp;范围内</li>
<li><code>0 &lt;= Node.val &lt;= 500</code></li>
<li><code>Node.val</code>&nbsp;中所有值 <strong>不同</strong></li>
<li>目标结点&nbsp;<code>target</code>&nbsp;是树上的结点。</li>
<li><code>0 &lt;= k &lt;= 1000</code></li>
</ul>
<p>&nbsp;</p>