#C7801. Mirror Trees Checker
Mirror Trees Checker
Mirror Trees Checker
In this problem, you are given two binary trees provided in level-order traversal. Each tree node is represented by an integer and missing nodes are denoted by the string null
. Two binary trees are considered mirror images if for every node in one tree, the corresponding node in the other tree exists such that the left subtree of one is the mirror image of the right subtree of the other, and vice versa. Formally, two trees with roots (r_1) and (r_2) are mirrors if
[ r_1.val = r_2.val, \quad areMirrors(r_1.left, r_2.right) \quad \text{and} \quad areMirrors(r_1.right, r_2.left) ]
Your task is to determine whether the two given trees are mirror images of each other.
inputFormat
The input consists of two lines. The first line contains the level-order traversal of the first binary tree, and the second line contains the level-order traversal of the second binary tree. The nodes are separated by a space, and missing nodes are represented by the string null
. An empty line indicates an empty tree.
outputFormat
Output a single line: print True
if the two trees are mirror images of each other, and False
otherwise.## sample
1 2 3
1 2 3
False