#C7578. Check Symmetric Binary Tree
Check Symmetric Binary Tree
Check Symmetric Binary Tree
Given a binary tree, determine whether it is symmetric.
A binary tree is symmetric if the left subtree is a mirror image of the right subtree. In mathematical terms, a binary tree is symmetric if for every node, (\text{isMirror}(\text{left}, \text{right})) holds, where (\text{isMirror}(L, R)) is defined recursively as: [ \text{isMirror}(L, R) = \begin{cases} True, & \text{if both } L \text{ and } R \text{ are null},\ False, & \text{if one of } L \text{ or } R \text{ is null},\ (L.val = R.val) \land \text{isMirror}(L.left, R.right) \land \text{isMirror}(L.right, R.left), & \text{otherwise.} \end{cases} ]
The binary tree is provided as a level-order traversal where the string "null" denotes a missing node. An empty tree is considered symmetric.
inputFormat
The input consists of a single line containing the level-order traversal of a binary tree. Each value is separated by a space. Use the string "null" to denote missing nodes. For example:
1 2 2 3 4 4 3
outputFormat
Output a single line with either "True" if the tree is symmetric or "False" if it is not.## sample
1 2 2 3 4 4 3
True
</p>