题目地址
LeetCode#199 Binary Tree Right Side View
题目描述
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
For example:
Given the following binary tree,
1 | 1 <--- |
You should return [1, 3, 4]
.
解题思路
这道题要求求出二叉树每一层最右边的值。那么我们只需要先序遍历,然后每一层依次更新就可以了。
解题代码
1 | /** |