Zero To DSAZero To DSA
Privacy Policy
Binary Tree Inorder Traversal

Maximum Depth of Binary Tree

easy
Time: O(n)
Space: O(h)

Given the root of a binary tree, return its maximum depth. The maximum depth is the number of nodes along the longest path from root to leaf.

Constraints

  • The number of nodes is in the range [0, 10⁴].

Examples

Input: root = [3,9,20,null,null,15,7]
Output: 3
Input: root = [1,null,2]
Output: 2