Problems/104. Maximum Depth of Binary Tree

104. Maximum Depth of Binary Tree

EasyBinary Tree

Given the root of a binary tree, compute 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 longest path is from root (3) -> (20) -> (15) or (3) -> (20) -> (7), which contains exactly 3 nodes.
Example 2
Input: root = [1, null, 2]
Output: 2
The longest path is from (1) -> (2), containing 2 nodes.
Example 3
Input: root = []
Output: 0
An empty tree has no nodes, so its depth is 0.
Visualizer

Visualizer will appear here