Loading…
Loading…
Given a binary tree, return its maximum depth (the number of nodes along the longest path from root to a leaf).
Input (level-order, null for missing): 3 9 20 null null 15 7
Output: 3
The depth of a tree is 1 (for the root itself) plus the deeper of its two subtrees' depths — a two-line recursive definition. An empty tree has depth 0.
Line 1: the tree in level-order, space-separated, null for a missing child (this is LeetCode's own tree-input convention)
Print the maximum depth.
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.