Compute the height of a binary tree node by node.
Constraints
Example
>>> # Example 1: tree = [3,9,20,None,None,15,7]
>>> root = {'val': 3, 'left': {'val': 9, 'left': None, 'right': None}, 'right': {'val': 20, 'left': {'val': 15, 'left': None, 'right': None}, 'right': {'val': 7, 'left': None, 'right': None}}}
>>> max_depth(root)
3
>>> # Example 2: empty tree
>>> max_depth(None)
0
>>> # Example 3: single node
>>> max_depth({'val': 1, 'left': None, 'right': None})
1
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints