Graph Theory37 sections · 1633 units
Open in Course

LeetCode 104 Maximum Depth of Binary Tree - Strategy

Recursive Definition

What is the max depth of a node? It is 11 (for itself) plus the max depth of its tallest child.

For a leaf, the max depth is 11 (itself). For an empty tree, the depth is 00.

This is a recursive definition. The base case is when the node is null (depth 00). The recursive case combines the depths of left and right children.

This pattern applies to many tree problems. Define the answer for a node in terms of the answers for its children.