1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/叶子相似的树 [leaf-similar-trees].html
2022-03-29 12:43:11 +08:00

39 lines
1.5 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>请考虑一棵二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个&nbsp;<strong>叶值序列 </strong></p>
<p><img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/16/tree.png" style="height: 336px; width: 400px;" /></p>
<p>举个例子,如上图所示,给定一棵叶值序列为&nbsp;<code>(6, 7, 4, 9, 8)</code>&nbsp;的树。</p>
<p>如果有两棵二叉树的叶值序列是相同,那么我们就认为它们是&nbsp;<em>叶相似&nbsp;</em>的。</p>
<p>如果给定的两个根结点分别为&nbsp;<code>root1</code>&nbsp;<code>root2</code>&nbsp;的树是叶相似的,则返回&nbsp;<code>true</code>;否则返回 <code>false</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/09/03/leaf-similar-1.jpg" style="height: 237px; width: 600px;" /></p>
<pre>
<strong>输入:</strong>root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]
<strong>输出:</strong>true
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/09/03/leaf-similar-2.jpg" style="height: 110px; width: 300px;" /></p>
<pre>
<strong>输入:</strong>root1 = [1,2,3], root2 = [1,3,2]
<strong>输出:</strong>false
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>给定的两棵树结点数在&nbsp;<code>[1, 200]</code> 范围内</li>
<li>给定的两棵树上的值在&nbsp;<code>[0, 200]</code> 范围内</li>
</ul>