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)/寻找重复的子树 [find-duplicate-subtrees].html

41 lines
1.3 KiB
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>给你一棵二叉树的根节点 <code>root</code> ,返回所有 <strong>重复的子树 </strong></p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>对于同一类的重复子树,你只需要返回其中任意 <strong>一棵 </strong>的根结点即可。</p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>如果两棵树具有<strong> 相同的结构</strong><strong>相同的结点值 </strong>,则认为二者是 <strong>重复 </strong>的。</p>
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/08/16/e1.jpg" style="height: 236px; width: 300px;" /></p>
<pre>
<strong>输入:</strong>root = [1,2,3,4,null,2,4,null,null,4]
<strong>输出:</strong>[[2,4],[4]]</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/08/16/e2.jpg" style="height: 125px; width: 200px;" /></p>
<pre>
<strong>输入:</strong>root = [2,1,1]
<strong>输出:</strong>[[1]]</pre>
<p><strong>示例 3</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/08/16/e33.jpg" style="height: 202px; width: 300px;" /></strong></p>
<pre>
<strong>输入:</strong>root = [2,2,2,3,null,3,null]
<strong>输出:</strong>[[2,3],[3]]</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
2023-12-09 18:42:21 +08:00
<li>树中的结点数在 <code>[1, 5000]</code> 范围内。</li>
2022-03-27 20:46:41 +08:00
<li><code>-200 &lt;= Node.val &lt;= 200</code></li>
</ul>