314. Binary Tree Vertical Order Traversal
Given a binary tree, return thevertical ordertraversal of its nodes' values. (ie, from top to bottom, column by column).
If two nodes are in the same row and column, the order should be from left to right.
Examples 1:
Input:
[3,9,20,null,null,15,7]
3
/\
/ \
9 20
/\
/ \
15 7
Output:
[
[9],
[3,15],
[20],
[7]
]Examples 2:
Examples 3:
FB: Complexity!
Thoughts
Use map <col, list<val>> to record the col and list value pair. Use BFS to expand the tree to add entry
Code T O(V), S O(V)
Python
Last updated
Was this helpful?