root, and a sample, pattern.
The subtree of a node is that node together with all of its descendants; the whole tree also counts as the subtree of its root. Return true if some node of root has a subtree identical to pattern, matching both in shape and in node values. Otherwise return false.root=tree_node([7, 2, 9, 1, 3]), pattern=tree_node([2, 1, 3]) → True
Node 2 together with all of its descendants is exactly pattern.
root=tree_node([7, 2, 9, 1, 3, None, None, 5]), pattern=tree_node([2, 1, 3]) → False
Node 1 has an extra child 5, so the subtree under node 2 is larger than pattern, and no exact copy exists.
root=tree_node([4, 4]), pattern=tree_node([4]) → True
The leaf 4 with its (empty) descendants matches pattern.
root has between 1 and 2000 nodespattern has between 1 and 1000 nodesroot=tree_node([7, 2, 9, 1, 3]), pattern=tree_node([2, 1, 3])
True
Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.