The problem. Given the root of a binary tree, return its maximum depth: the number of nodes on the longest path from the root down to a leaf. An empty tree has depth 0.
Input: root = [3, 9, 20, null, null, 15, 7] Output: 3
Input: root = [1, null, 2] Output: 2
Input: root = [] Output: 0LeetCode's "depth" counts nodes, so it equals the height in edges plus one. The question is really: how many levels does the tree have?
Free account
Sign up to read the rest of this lesson: 6 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come