dsa · easy
Height of Binary Tree
GreyOrangeTreeRecursionFoundation
A binary tree node is [val, left, right] or None. Return the **number of nodes** on the longest root-to-leaf path (empty tree is 0).
Arguments
root— the binary tree; each node is[val, left, right]orNone
**Example:** [3, [9, None, None], [20, [15, None, None], [7, None, None]]] → 3.
Constraints
Number of nodes in [0, 10^4] Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [3, [9, None, None], [20, [15, None, None], [7, None, None]]] Expected: 3
Example 2
Input: None Expected: 0