#C8060. Maximum Depth of Binary Tree

    ID: 52001 Type: Default 1000ms 256MiB

Maximum Depth of Binary Tree

Maximum Depth of Binary Tree

Given a binary tree, compute its maximum depth. The maximum depth is defined as the number of nodes along the longest path from the root node down to the farthest leaf node. Formally, if (r) is the root, then the maximum depth (d) is given by [ d = \begin{cases}0, & \text{if } r \text{ is null},\1 + \max(\text{maxDepth}(r.left),,\text{maxDepth}(r.right)), & \text{otherwise.} \end{cases} ] An empty tree has a depth of 0.

inputFormat

Input is provided as a single line containing space-separated values representing the binary tree in level order. Use the string null to denote a missing node. For example, the tree [3, 9, 20, null, null, 15, 7] is given as:

3 9 20 null null 15 7

outputFormat

Output a single integer representing the maximum depth of the binary tree.## sample

null
0

</p>