1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/二叉树的堂兄弟节点 [cousins-in-binary-tree].html
2022-03-29 12:43:11 +08:00

45 lines
1.7 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>在二叉树中,根节点位于深度 <code>0</code> 处,每个深度为 <code>k</code> 的节点的子节点位于深度 <code>k+1</code> 处。</p>
<p>如果二叉树的两个节点深度相同,但<strong> 父节点不同</strong> ,则它们是一对<em>堂兄弟节点</em></p>
<p>我们给出了具有唯一值的二叉树的根节点 <code>root</code> ,以及树中两个不同节点的值 <code>x</code><code>y</code></p>
<p>只有与值 <code>x</code><code>y</code> 对应的节点是堂兄弟节点时,才返回 <code>true</code> 。否则,返回 <code>false</code></p>
<p> </p>
<p><strong>示例 1<br />
<img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/16/q1248-01.png" style="height: 160px; width: 180px;" /></strong></p>
<pre>
<strong>输入:</strong>root = [1,2,3,4], x = 4, y = 3
<strong>输出:</strong>false
</pre>
<p><strong>示例 2<br />
<img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/16/q1248-02.png" style="height: 160px; width: 201px;" /></strong></p>
<pre>
<strong>输入:</strong>root = [1,2,3,null,4,null,5], x = 5, y = 4
<strong>输出:</strong>true
</pre>
<p><strong>示例 3</strong></p>
<p><strong><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/16/q1248-03.png" style="height: 160px; width: 156px;" /></strong></p>
<pre>
<strong>输入:</strong>root = [1,2,3,null,4], x = 2, y = 3
<strong>输出:</strong>false</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>二叉树的节点数介于 <code>2</code> 到 <code>100</code> 之间。</li>
<li>每个节点的值都是唯一的、范围为 <code>1</code> 到 <code>100</code> 的整数。</li>
</ul>
<p> </p>