80. Symmetric Tree
Determine whether the left and right sides of the tree are mirror images around the root. Corresponding values must match when left and right directions are exchanged.
A symmetric tree is defined by mirrored positions, not by having the same values on both sides in arbitrary order.
Example 1
Input
[1,2,2,3,4,4,3]
Output
true
Explanation: Opposite positions match through both levels.
Example 2
Input
[1,2,2,null,3,null,3]
Output
false
Explanation: Both 3s lie on right edges of their parents; their null positions do not mirror.
Constraints
0 <= node count per tree <= 105-231 <= node.value <= 231 - 1- Each input is a proper binary tree: no cycles or shared child nodes. Null trees are permitted.
Hints
Hint 1
Which child of the right subtree mirrors the left child of the left subtree?
Hint 2
A missing position has to mirror another missing position.
Hint 3
Start with the root children and repeatedly compare crossed child pairs.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Outer and inner mirror pairs
[1,2,2,3,4,4,3]
true