tree. Find its height: the number of nodes on the longest downward path from the root to any leaf, counting both the root and the leaf.
An empty tree has height 0, and a single-node tree has height 1.tree=tree_node([5, 2, 8, None, 4, None, None, 3]) → 4
The longest branch is 5 → 2 → 4 → 3, which has four nodes.
tree=tree_node([]) → 0
The tree is empty, so its height is 0.
tree=tree_node([-7]) → 1
tree=tree_node([5, 2, 8, None, 4, None, None, 3])
4
Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.