#C10738. Check Symmetric Binary Tree

    ID: 39976 Type: Default 1000ms 256MiB

Check Symmetric Binary Tree

Check Symmetric Binary Tree

Given a binary tree, determine whether it is a mirror of itself (i.e., symmetric around its center). The tree is provided in level order traversal, where null represents a missing node. A binary tree is symmetric if its left subtree is a mirror reflection of its right subtree. Formally, the mirror condition can be defined as:

$$isMirror(t_1, t_2)=\big(t_1.val = t_2.val\big) \land isMirror(t_1.left, t_2.right) \land isMirror(t_1.right, t_2.left) $$

Output true if the tree is symmetric and false otherwise.

inputFormat

A single line of input representing the level order traversal of a binary tree. The node values are separated by spaces. Each node is an integer or the string null to denote missing nodes. For example: 1 2 2 3 4 4 3 represents a complete binary tree.

outputFormat

A single line output: true if the binary tree is symmetric, and false otherwise.## sample

1 2 2 3 4 4 3
true