📘
Same Tree
EasyTrees
Given two binary trees (level-order arrays), check if they are structurally identical with the same node values.
Example:
Input:
1,2,3 1,2,3
Output:
True
Reasoning:
- The two input arrays
1,2,3and1,2,3represent two binary trees in level-order traversal. - We compare the two arrays node by node: both have the same root node value
1, the same left child node value2, and the same right child node value3. - Since the arrays have the same length and all corresponding node values match, we conclude that the two binary trees are structurally identical with the same node values.
- The function returns
True, indicating that the two input trees are the same.
Constraints:
- 0 <= number of nodes <= 100
- -10^4 <= Node.val <= 10^4
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.