The problem. Given the roots of two binary trees, root and subRoot, return true if some node of root has a subtree that is exactly the same as subRoot — the same structure and values, all the way down to the leaves.
root = [3, 4, 5, 1, 2], subRoot = [4, 1, 2] -> true
root = [3, 4, 5, 1, 2, null, null, null, null, 0], subRoot = [4, 1, 2] -> false"Exactly" matters: in the second example, the subtree under 4 has an extra 0 below 2, so it only *contains* subRoot's nodes — it isn't the same tree. A match must also stop where subRoot stops.
Free account
Sign up to read the rest of this lesson: 6 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come