#C5028. Count the Number of Nodes in a Binary Tree

    ID: 48632 Type: Default 1000ms 256MiB

Count the Number of Nodes in a Binary Tree

Count the Number of Nodes in a Binary Tree

You are given a binary tree represented in level order as a series of tokens separated by spaces. Each token is either an integer representing a node's value or the string null representing a missing node. Your task is to count the total number of nodes in the binary tree.

The tree may be full, complete, or even unbalanced. Note that if the input is just null, then the tree is empty and the answer is 0.

Note: The input is given via standard input and the output should be printed to standard output.

inputFormat

The input consists of a single line containing the level order traversal of the binary tree. The node values are separated by spaces. Use the string null to denote a missing child.

For example:

1 2 3 4 null 6 null

outputFormat

Output a single integer: the total number of nodes in the binary tree.

For example, the output for the above input should be:

5
## sample
1
1

</p>