Loading problem...
Given the root node of a binary tree, determine whether the tree exhibits mirror symmetry—that is, whether the tree is structurally and value-wise identical when reflected across its central vertical axis.
A binary tree is considered mirror-symmetric if you were to draw an imaginary vertical line through its root, the left subtree would be a perfect reflection of the right subtree. This means:
Your task is to implement an algorithm that efficiently validates this mirror property for any given binary tree.
root = [1,2,2,3,4,4,3]trueThe tree has perfect mirror symmetry. The left subtree [2,3,4] is a mirror reflection of the right subtree [2,4,3]. Node values at corresponding mirrored positions are equal: left's outer child (3) matches right's outer child (3), and left's inner child (4) matches right's inner child (4).
root = [1,2,2,null,3,null,3]falseAlthough both children of the root have value 2, the structure is not mirrored. The left subtree has a right child with value 3, while the right subtree also has a right child with value 3. For mirror symmetry, the left subtree's right child should correspond to the right subtree's left child, not its right child.
root = [1,2,2]trueA simple three-node tree where both children have the same value and no further descendants. This is trivially symmetric as both subtrees are identical single-node structures.
Constraints