← 返回 meta 的题目列表Print Binary Tree Side View
类型:online_judge
Print the side view of a binary tree: Print the left side first from bottom to top, then print the right side from top to bottom. Only record the outermost numbers of each level. If a level has only one node, it can be recorded twice. Use BFS to record the first node of each level (save to res_left[]) and the last node (save to res_right[]). Finally, reverse res_left and add res_right for printing.
Example
Input
{"root": [1,2,3,null,5]}