Given the root of a binary tree, return the leftmost value in the last row of the tree.
Example 1:
Input: {"root":[2,1,3]}
Output: 1
Constraints:
The number of nodes in the tree is in the range [1,104].
−231≤Node.val≤231−1
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"root":[2,1,3]}
Run a breadth-first search, but enqueue the right child before the left. Each row then leaves the queue from right to left, so the very last node out is the leftmost node of the deepest row.