📘
Symmetric Tree
EasyTrees & BFS
Given the root of a binary tree (as a level-order array), check whether it is a mirror of itself (symmetric around its center).
Example:
Input:
1,2,2,3,4,4,3
Output:
True
Reasoning:
- The input array
1,2,2,3,4,4,3represents a binary tree in level-order traversal, which can be visualized as: 1 /
2 2 / \ /
3 4 4 3 - To check for symmetry, we compare the left and right subtrees.
- The left subtree is a mirror of the right subtree: both have the same structure and node values when reflected around the center.
- Since the tree is symmetric around its center, the function returns
Trueindicating that the tree is a mirror of itself.
Constraints:
- 1 <= number of nodes <= 1000
- -100 <= Node.val <= 100
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.