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
2
3
4
5
6 1 <---
/ \
2 3 <---
\ \
5 4 <---You should return
[1, 3, 4]
.
我用DFS对二叉树进行遍历, 先遍历右节点再遍历左节点. 把每次遍历到的新的一层的第一个节点加入结果中.
1 | /** |