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)/子结构判断 [shu-de-zi-jie-gou-lcof].html
2023-12-09 18:53:53 +08:00

34 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>tree1</code><code>tree2</code>,判断 <code>tree2</code> 是否以 <code>tree1</code> 的某个节点为根的子树具有 <strong>相同的结构和节点值</strong><br />
注意,<strong>空树&nbsp;</strong>不会是以 <code>tree1</code> 的某个节点为根的子树具有 <strong>相同的结构和节点值</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p>&nbsp;</p>
<p><img alt="" src="https://pic.leetcode.cn/1694684670-vwyIgY-two_tree.png" /></p>
<p>&nbsp;</p>
<pre>
<strong>输入:</strong>tree1 = [1,7,5], tree2 = [6,1]
<strong>输出:</strong>false
<strong>解释:</strong>tree2 与 tree1 的一个子树没有相同的结构和节点值。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1694685602-myWXCv-two_tree_2.png" /></p>
<pre>
<strong>输入:</strong>tree1 = [3,6,7,1,8], tree2 = [6,1]
<strong>输出:</strong>true
<strong>解释:</strong>tree2 与 tree1 的一个子树拥有相同的结构和节点值。即 6 - &gt; 1。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<p><code>0 &lt;= 节点个数 &lt;= 10000</code></p>