Dashboard
#26. Maximum Depth of Binary TreeEasyTrees

Given the root of a binary tree, return its depth.

The depth of a binary tree is defined as the number of nodes along the longest path from the root node down to the farthest leaf node.

Example 1:

Input: root = [1,2,3,null,null,4]

Output: 3

Example 2:

Input: root = []

Output: 0

Constraints:

  • 0 <= The number of nodes in the tree <= 100.
  • -100 <= Node.val <= 100
Examples
Example 1:
Input: root = [1,2,3,null,null,4]
Output: 3
Example 2:
Input: root = []
Output: 0
Constraints
  • `0 <= The number of nodes in the tree <= 100`.
  • `-100 <= Node.val <= 100`
Prerequisites
Target: O(N) time • O(1) spaceTree / Depth-First Search / Breadth-First Search / Binary Tree
Socratic AI Tutor
Gemini 3.8 Flash
Loading editor...

Click "Run" or press Ctrl+Enter to execute test cases.