Loading...
Loading...
You are given the root of a binary tree, root. Return the value of its deepest node, where the root has depth 0.
If more than one node is at the maximum depth, return the leftmost one: the node that comes first when that depth's nodes are listed left to right, in the same order as a level-order traversal.
Your function receives root as a TreeNode. The node type is provided for you, with val, left, and right fields.
The examples below write the tree as its level-order traversal, where null marks a missing child of a listed node and trailing nulls are omitted. That is only how the input is displayed; the decoding is done for you.
root is in the range [1,105].Node.val ≤109The deepest level is depth 2, holding `4`, `5`, and `6` in left-to-right order. The leftmost of them is `4`.
Node `2` has no children, so the deepest level (depth 2) only comes from `3`'s subtree: `4` and `5`. The leftmost is `4`.
The single node `1` is its own deepest node.