← 返回 meta 的题目列表Binary Tree Side View (Left and Right)
类型:online_judge
Given the root of a binary tree root, return two views:
Left side view: for each depth/level, the first node visible when looking from the left.
Right side view: for each depth/level, the first node visible when looking from the right.
Return two integer arrays leftView and rightView.
Input
A binary tree root
Output
leftView: visible node values from top to bottom, taking the leftmost node at each level
rightView: visible node values from top to bottom, taking the rightmost node at each level
Constraints
0 <= n <= 1e5 nodes
Node values are 32-bit signed integers
Examples
Example 1:
Input: [1,2,3,null,5,null,4]
Output:
leftView = [1,2,5]
rightView = [1,3,4]
Example 2:
Input: []
Output:
leftView = []
rightView = []
Example
Input
[1,2,3,null,5,null,4]
Output
leftView=[1,2,5]
rightView=[1,3,4]