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.
|
|
题目大意
给定一二叉树,求二叉树的右视图。
例如,从右边看二叉树,你应该返回结果为:[1, 3, 4]。
解题思路
层序遍历,辅助栈。
只将当前层的最右节点加入数组,通过flag参数标记当前层是否已经有节点被加入到数组内。
代码
|
|