#C351. Minimum Depth of Binary Tree
Minimum Depth of Binary Tree
Minimum Depth of Binary Tree
Given a binary tree, determine its minimum depth. The minimum depth is defined as the number of nodes along the shortest path from the root node down to the nearest leaf node. A leaf is a node with no children.
The input is provided as a comma-separated list representing a level-order traversal of the tree, where the string null
indicates a missing node. You may assume that the list represents a valid binary tree.
Note: If the tree is empty, the minimum depth is 0.
inputFormat
A single line containing a comma-separated list of node values representing the binary tree in level-order. Use "null" (without quotes) for missing nodes. For example: 1,2,3,4,5,null,null
outputFormat
Print a single integer representing the minimum depth of the binary tree.## sample
1,2,3,4,5,null,null
2