Subtree of Another Tree
Return True if some node of root has a subtree that is exactly the same as subRoot (same shape and same values, and that node must include all of its descendants). Otherwise return False. The tree root itself counts as one of its own subtrees.
Trees appear in the tests in level order, with null for a missing child, like [3,9,20,null,null,15,7]. Each node is a TreeNode with .val, .left and .right; the class is already defined for you.
Example 1
root [3,4,5,1,2]
subRoot [4,1,2]
returns true
The subtree at node 4 matches.
Example 2
root [3,4,5,1,2,null,null,0]
subRoot [4,1,2]
returns false
The 4 in root has an extra child 0 below 2, so it does not match.
Constraints
1 <= number of nodes in each tree <= 100-100 <= node.val <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.