time O(n)
space O(h)
State Variables
currDepth0
maxDepth0
Curr Depth0
Max Depth0
3
9
20
15
7
Start DFS to find the maximum depth.
Pseudocode
Pseudocode
1function maxDepth(root):
2 if root is null:
3 return 0
4 left_depth = maxDepth(root.left)
5 right_depth = maxDepth(root.right)
6 return max(left_depth, right_depth) + 1