Return whether root contains a node whose entire rooted subtree has the same structure and values as subRoot.
Example 1
Argument 1 tree: level-order input; omitted children are null.Argument 2 tree: level-order input; omitted children are null.root = [5,3,8,1,4]
subRoot = [3,1,4]
true
Explanation
The entire subtree rooted at 3 matches [3,1,4].
Example 2
Argument 1 tree: level-order input; omitted children are null.Argument 2 tree: level-order input; omitted children are null.root = [5,3,8,1,4,null,null,0]
subRoot = [3,1,4]
false
Explanation
The candidate subtree has an extra descendant 0; matching its first values is insufficient.
Example 3
Argument 1 tree: level-order input; omitted children are null.Argument 2 tree: level-order input; omitted children are null.root = [2]
subRoot = [2]
true
Explanation
A tree is a subtree of itself, including this singleton.
Constraints
- 1 <= nodes in each tree <= 2000
- Trees are breadth-first arrays with null holes
Function contractisSubtreeArguments: tree, tree