mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定两棵二叉树 <code>tree1</code> 和 <code>tree2</code>,判断 <code>tree2</code> 是否以 <code>tree1</code> 的某个节点为根的子树具有 <strong>相同的结构和节点值</strong> 。<br />
 | 
						||
注意,<strong>空树 </strong>不会是以 <code>tree1</code> 的某个节点为根的子树具有 <strong>相同的结构和节点值</strong> 。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><img alt="" src="https://pic.leetcode.cn/1694684670-vwyIgY-two_tree.png" /></p>
 | 
						||
 | 
						||
<p> </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 - > 1。</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<p><code>0 <= 节点个数 <= 10000</code></p>
 |