Check Identical Trees
Easyjavapythonccppjavascript
Given two binary trees, determine whether they have exactly the same structure and the same value at every corresponding node.
Input Format
The first line contains an integer M1 and the second line the M1 level-order tokens of tree A (blank if M1 is 0). The third line contains an integer M2 and the fourth line the M2 level-order tokens of tree B (blank if M2 is 0).
Output Format
Print 1 if the trees are identical, otherwise print 0.
Example 1
Input
3 1 2 3 3 1 2 3
Output
1
Explanation: Both trees have matching structure and values.
- 0 <= number of nodes in each tree <= 5000
- -1000000000 <= node value <= 1000000000
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Inorder TraversalEasy · java, python, c, cpp, javascriptSolve Problem
- Preorder TraversalEasy · java, python, c, cpp, javascriptSolve Problem
- Postorder TraversalEasy · java, python, c, cpp, javascriptSolve Problem