#K59447. Uni-value Binary Tree Check
Uni-value Binary Tree Check
Uni-value Binary Tree Check
You are given a binary tree in level-order traversal. The tree is represented as a sequence of values separated by spaces. Missing nodes are represented by the string null
.
A binary tree is called uni-value if every node in the tree has the same value. Formally, if the root has value \(x\), then for every node in the tree the value must be \(x\). An empty tree is considered uni-value.
Your task is to determine whether the given binary tree is uni-value.
Note: Input is taken from standard input and output should be sent to standard output.
inputFormat
The input consists of a single line containing the level-order traversal of the binary tree. The values are separated by spaces. Use null
to indicate a missing node.
For example:
1 1 1 1 1 null null
outputFormat
Output a single line: True
if the tree is uni-value, otherwise False
.
1 1 1 1 1 null null
True