Given the root of a binary tree, return its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Pattern focus: Recursive Tree Metrics. Compute the depth of each subtree and take the maximum.
root = binary tree root
maximum depth of the tree
Example 1:
Input:
root = [3,9,20,null,null,15,7]
Output:
3
Explanation:
The longest root-to-leaf path has 3 nodes.
Example 2:
Input:
root = [1,null,2,3]
Output:
3
Explanation:
The path 1 -> 2 -> 3 has depth 3.