Given the root of a binary tree, return its maximum depth — the number of nodes along the longest path from the root node down to the farthest leaf node.
Example 1
Input: root = [3,9,20,null,null,15,7]
Output: 3
The number of nodes is in the range [0, 10^4].Recursion: depth = 1 + max(depth(left), depth(right))
public int maxDepth(TreeNode root) {
if (root == null) return 0;
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}Time: O(n) · Space: O(h)