57. Symmetric Tree
Easy · Binary Tree
Given a binary tree, determine if it is symmetric around its center. A tree is symmetric if the left subtree is a mirror reflection of the right subtree.
Two trees are mirrors of each other if: - Their roots have the same value - The left subtree of the first tree mirrors the right subtree of the second tree - The right subtree of the first tree mirrors the left subtree of the second tree
Examples
Example 1 Input: [1, 2, 2, 3, 4, 4, 3] Output: true Explanation: The tree is symmetric. The left subtree (rooted at 2 with children 3, 4) mirrors the right subtree (rooted at 2 with children 4, 3).
Example 2 Input: [1, 2, 2, null, 3, null, 3] Output: false Explanation: The tree is not symmetric. The left subtree has a right child (3) but the right subtree has a left child (3), breaking the mirror property.
Constraints
- Standard input/output constraints apply