Solution: Subtree of Another Tree
Let's solve the Subtree of Another Tree problem using Tree Depth First Search pattern.
We'll cover the following...
We'll cover the following...
Statement
Given the roots of two binary trees, root and sub_root, return TRUE if there is a subtree of root with the same structure and nodes as sub_root. Otherwise, return FALSE.
A tree can only be considered a subtree of the root tree iff all the descendants (children) of the node appear in sub_root.
Constraints:
The number of nodes in the
roottree is in the rangeThe number of nodes in the
sub_roottree is in the range...