Class Solution
java.lang.Object
g0501_0600.s0572_subtree_of_another_tree.Solution
572 - Subtree of Another Tree.<p>Easy</p>
<p>Given the roots of two binary trees <code>root</code> and <code>subRoot</code>, return <code>true</code> if there is a subtree of <code>root</code> with the same structure and node values of <code>subRoot</code> and <code>false</code> otherwise.</p>
<p>A subtree of a binary tree <code>tree</code> is a tree that consists of a node in <code>tree</code> and all of this node’s descendants. The tree <code>tree</code> could also be considered as a subtree of itself.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/04/28/subtree1-tree.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [3,4,5,1,2], subRoot = [4,1,2]</p>
<p><strong>Output:</strong> true</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/04/28/subtree2-tree.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [3,4,5,1,2,null,null,null,null,0], subRoot = [4,1,2]</p>
<p><strong>Output:</strong> false</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the <code>root</code> tree is in the range <code>[1, 2000]</code>.</li>
<li>The number of nodes in the <code>subRoot</code> tree is in the range <code>[1, 1000]</code>.</li>
<li><code>-10<sup>4</sup> <= root.val <= 10<sup>4</sup></code></li>
<li><code>-10<sup>4</sup> <= subRoot.val <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isSubtree
-