Count Leaf Nodes
Easyjavapythonccppjavascript
Count the number of nodes in a binary tree that have no children.
Input Format
The first line contains an integer M, the number of level-order tokens. The second line contains M space-separated tokens (integers or null). It is blank when M is 0.
Output Format
Print the number of leaf nodes.
Example 1
Input
5 1 2 3 4 5
Output
3
Explanation: Nodes 4, 5 and 3 are leaves.
- 0 <= number of nodes <= 5000
- -1000000000 <= node value <= 1000000000