Maximum Depth of Binary Tree - aloalgo

Maximum Depth of Binary Tree

Easy

You are given the root of a binary tree.

Your task is to return the maximum depth of the binary tree. The maximum depth is defined as the total number of nodes along the longest path from the root down to the farthest leaf node.

Remember that:

  • A leaf node is a node that has no children.

Example 1

Input
12485367
Output
4
Explanation:

The longest path is 1 -> 2 -> 4 -> 8, which has 4 nodes.

Example 2

Input
12
Output
2
Explanation:

The longest path is 1 -> 2, which has 2 nodes.

Example 3

Input
None
Output
0
Explanation:

The tree is empty, so its depth is 0.

Loading...
Input
12485367
Output
4

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!