45. Maximum Depth of Binary Tree

Return the maximum depth of a binary tree: the number of nodes on the longest path from the root down to a leaf. Trees are given in level order, with null for a missing child.

Example 1

Input: root = [3,9,20,null,null,15,7]
Output: 3

Example 2

Input: root = [1,null,2]
Output: 2
Hint 1

Depth of a node = 1 + the larger depth of its two subtrees.

TreeDFSBFS