← 返回 bytedance 的题目列表Binary Tree Right Side View (Build tree + write your own test cases)
类型:online_judge
Problem: Binary Tree Right Side View (Build the tree + write your own test cases)
Given the root root of a binary tree, return the values of the nodes you can see when looking at the tree from the right side, ordered from top to bottom.
Requirements
You need to define the binary tree node structure yourself (e.g., TreeNode) and build the tree from the input.
Implement the algorithm and write your own test cases to validate correctness.
Suggested Input Format
Use a level-order array representation of the binary tree, e.g. [1,2,3,null,5,null,4], where null indicates a missing node.
Output Format
Return an integer array representing the right side view.
Constraints
Number of nodes n: 0 <= n <= 10^4
Node value range: -10^9 <= val <= 10^9
Example
Input: [1,2,3,null,5,null,4]
Output: [1,3,4]
Example
Input
[1,2,3,null,5,null,4]
Output
[1,3,4]