FastPrepMaximum Depth of Binary Tree
Problem · Tree

Maximum Depth of Binary Tree

Learn this problem
EasyLinkedIn logoLinkedInFULLTIMEPHONE SCREEN

Problem statement

Given the root of a finite binary tree, return its maximum depth: the number of nodes on the longest path from the root to a leaf. Return 0 for an empty tree.

Function

maximumDepth(root: TreeNode) → int

Examples

Example 1

root = [3,9,20,null,null,15,7]return = 3

The longest root-to-leaf path contains three nodes.

Example 2

root = []return = 0

An empty tree has depth zero.

Constraints

  • The tree contains at most 100000 nodes.
  • Every node value fits in a signed 32-bit integer.
  • The input is a finite acyclic binary tree.

More LinkedIn problems

drafts saved locally
public int maximumDepth(TreeNode root) {
    // Write your code here.
}
root[3,9,20,null,null,15,7]
expected3
checking account