Leetcode Problem 513. Find Bottom Left Tree Value

513. Find Bottom Left Tree Value

Leetcode Solutions

Breadth-First Search (BFS) to find the leftmost value in the last row

  1. Initialize a queue and enqueue the root node along with its level (starting from 0).
  2. While the queue is not empty, perform the following steps: a. Dequeue a node from the queue and record its level. b. If the current level is greater than the previously recorded level, update the answer with the current node's value as it is the first node of the new level. c. Enqueue the left child of the current node if it exists, along with the next level number. d. Enqueue the right child of the current node if it exists, along with the next level number.
  3. Continue the process until the queue is empty. The answer recorded will be the leftmost value in the last row of the tree.
UML Thumbnail

Depth-First Search (DFS) to find the leftmost value in the last row

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...