Maximum Height of Binary Tree

Problem Return the maximum depth of a binary tree — the number of nodes on the longest root-to-leaf path.

Input / Output

  • Input: the tree root.
  • Output: an int depth (0 for an empty tree).

Constraints

  • Up to 10^4 nodes; O(n) required; recursion depth equals the tree height (mention skew).

Example

  • [3,9,20,null,null,15,7] -> 3.
asked …
LeaderboardSalaryAccount