Symmetric example
Input
root = TreeNode(1, TreeNode(2, TreeNode(3), TreeNode(4)), TreeNode(2, TreeNode(4), TreeNode(3)))
Output
True
Left and right subtrees are mirrors of each other.
Full lesson preview
Determine whether a binary tree is a mirror of itself (symmetric around its center).
Problem statement
Task
Examples
Input
root = TreeNode(1, TreeNode(2, TreeNode(3), TreeNode(4)), TreeNode(2, TreeNode(4), TreeNode(3)))
Output
True
Left and right subtrees are mirrors of each other.
Input format
Output format
Constraints
Samples
Input
TreeNode(1, TreeNode(2, None, TreeNode(3)), TreeNode(2, None, TreeNode(3)))
Output
False
Structure not mirrored even though some values match.