#C14417. Symmetric Binary Tree
Symmetric Binary Tree
Symmetric Binary Tree
Given the level order traversal of a binary tree, determine whether the tree is symmetric around its center. A binary tree is symmetric if the left subtree is a mirror reflection of the right subtree.
For example, the tree represented by 1 2 2 3 4 4 3
is symmetric, whereas 1 2 2 null 3 null 3
is not symmetric.
The tree is provided via standard input. Your program should build the tree, check its symmetry, and output either True
or False
to standard output.
inputFormat
The input consists of a single line containing a space-separated list of node values in level order. The value null
represents a missing node. If the input is empty (or only contains whitespace), the tree is considered empty.
outputFormat
Output a single line with either True
or False
, indicating whether the binary tree is symmetric.
1 2 2 3 4 4 3
True