← Practice · Trees
Maximum Depth of Binary Tree Easy
Given the root of a binary tree (TreeNode with val, left, right; null for empty), return its maximum depth: the number of nodes along the longest path from the root down to a leaf.
Examples
[3,9,20,null,null,15,7] -> 3[] -> 0
Define a function named maxDepth in JavaScript. TreeNode (val, left, right) is available.
00:00▶ Visualize
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests