#C13013. Sum of Binary Tree Nodes
Sum of Binary Tree Nodes
Sum of Binary Tree Nodes
You are given a binary tree represented in level order where each node's value is provided as a space-separated token. Use the token null
to represent a missing node. Your task is to compute the sum of all node values in the tree.
For example, the input "1 2 3" represents the following binary tree:
1 / \ 2 3
The sum of the nodes is \(1+2+3=6\).
The input is given via standard input and the output (the sum of node values) should be printed to standard output.
inputFormat
The input is a single line containing the level order traversal of the binary tree. Each token is separated by a space. Use null
to denote a missing child node. If the tree is empty, the input will be a single token null
.
outputFormat
Output a single integer: the sum of all the nodes in the binary tree.
## samplenull
0