You get the roots p and q of two binary trees. Return true if the two trees are identical and false otherwise.
Two trees are identical when they have exactly the same shape and every node in one holds the same value as the node in the same position in the other. Two empty trees are identical.
The values match, but in p the 3 is the left child of 6 and in q it is the right child.
Constraints
0 and 100 nodes.-10⁴ <= Node.val <= 10⁴Two trees are identical when their roots hold the same value, their left subtrees are identical and their right subtrees are identical. That's the same question again, one level down.
Put the two trees side by side and lay a finger on each root. The trees are identical when, wherever one finger can go, the other can go too, and the two nodes under your fingers always hold the same value.
Time O(min(n, m))Space O(h)
The full walkthrough and code are part of Premium
true