199. Binary Tree Right Side View -BFS

this part is the key point

or

time: O(n)

space: O(D) to keep the queues, where D is a tree diameter. Let's use the last level to estimate the queue size. This level could contain up to N/2N/2 tree nodes in the case of complete binary tree.

DFS

use preorder (because not related to subtree)

how to know current depth? use a varible

Last updated

Was this helpful?