#8

Maximum Depth of Binary Tree

Easy
All Problems

8. Maximum Depth of Binary Tree#104

Easy🌳 TreesRecursive Depth

Find the maximum depth (number of nodes along the longest root-to-leaf path) of a binary tree.

Examples

Example 1:
Input: [[3,9,20,null,null,15,7]]
Output: 3
Example 2:
Input: [[1,null,2]]
Output: 2
Example 3:
Input: [[]]
Output: 0

Why learn this

The simplest tree recursion problem — just count levels. Perfect introduction to DFS.

TreesDFSBFSRecursion
Python 3Loading Python engine...
Click "Run Code" to test your solution