Check if Tree is Symmetric
Medium Acceptance 74.98% Points 30.00
You are given the root of a binary tree. Your task is to determine whether the tree is symmetric around its center.
A binary tree is considered symmetric if:
- The left subtree is a mirror image of the right subtree.
- Corresponding nodes on both sides have the same values.
- The structure of both subtrees is also mirrored.
Examples
Example 1
Input: root = [1,2,2,3,4,4,3]
Output: true
Explanation: The left and right subtrees are mirror images of each other.
Example 2
Input: root = [1,2,2,null,3,null,3]
Output: false
Explanation: The left and right subtrees are not mirror images.
Example 3
Input: root = []
Output: true
Explanation: An empty tree is symmetric.
Constraints
- 0 = Number of nodes = 105
Companies
Atlassian ServiceNow
Topics
Tree Traversal Binary Tree
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.