Loading...
Given two binary trees root and subRoot (as level-order arrays), return True if subRoot is a subtree of root.
A subtree is a node and all its descendants matching exactly.
3,4,5,1,2 4,1,2
True
root is constructed from the level-order array: 3,4,5,1,2, resulting in a tree with 3 as the root, 4 and 5 as its children, and 1 and 2 as children of 4.subRoot is constructed from the level-order array: 4,1,2, resulting in a tree with 4 as the root and 1 and 2 as its children.subRoot is a subtree of root by comparing the structure and node values of subRoot with the corresponding subtree of root rooted at node 4.root rooted at node 4 has the same structure and node values as subRoot, we conclude that subRoot is a subtree of root, resulting in an output of True.