Beginner
Open
Pro
Binary Tree Symmetry
Given the root of a binary tree, determine whether it is a mirror of itself — that is, the left subtree is a mirror reflection of the right subtree.
Example 1
Input: [1, 2, 2, 3, 4, 4, 3]
1
/ \
2 2
/ \ / \
3 4 4 3
Output: true.
Example 2
Input: [1, 2, 2, null, 3, null, 3]
1
/ \
2 2
\ \
3 3
Output: false — the two 3 nodes are both on the "inner" side
relative to the mirror axis, so this is not symmetric even though
both subtrees look superficially similar.
Example 3
Input: [] → Output: true (an empty tree is trivially symmetric).
Constraints
- The number of nodes is in the range
[1, 1000]. -100 <= Node.val <= 100.
Share this question