LeetCode75-199-BT-Right-Side-View
🧠 Summary of Thoughts
Idea
Use level-order traversal (BFS) to process the tree level by level. For each level, record the last node because it represents the node visible from the right side.
Steps
Use a
queueto perform BFS.For each level, get the number of nodes:
size = queue.size().Traverse all nodes in that level.
When visiting the last node of the level (
i == size - 1), add its value to the result.Push the node’s left and right children into the queue.
When to use BFS?
- Level by Level
- shortest path
- spread from one spot
✅ Code(Java)
1 | |
1 | |
LeetCode75-199-BT-Right-Side-View
https://powersixxx.github.io/leetcode-blog/2026/03/07/LeetCode75-199-BT-Right-Side-View/