Subtree of Another Tree
ID:572
Last updated
ID:572
Last updated
Given the roots of two binary trees root
and subRoot
, return true
if there is a subtree of root
with the same structure and node values of subRoot
and false
otherwise.
A subtree of a binary tree tree
is a tree that consists of a node in tree
and all of this node's descendants. The tree tree
could also be considered as a subtree of itself.
When a node that is the same as the root of subRoot is found, do BFS to check all corresponding elements to see if the subtree is valid
Else check both the left and right sub part of current root to see if any node that matches the root of subRoot exists in these sub parts, then do BFS check