Check if Two Binary Trees are Identical
Given the roots of two binary trees, determine if the trees are identical or not.
Statement
Given the roots of two binary trees, determine if the trees are identical or not.
Examples
Example 1
Identical trees have the same layout and data at each node. Consider the following two binary trees with the same structure and data:
Sample input
The input lists below represent the in-order traversal of the two binary trees:
[25, 50, 100, 125, 200, 350], [25, 50, 100, 125, 200, 350]
Expected output
true
Example 2
Trees with the same data are not necessarily identical, as they may not be the same in terms of their structure. For example, if we look at the two trees below, they are not identical even though they have the same data:
Sample input
The input lists below represent the in-order traversal of the two binary trees:
[50, 25, 100, 125, 200, 350], [25, 50, 100, 125, 200, 350]
Expected output
false