【Leetcode 199】Binary Tree Right Side View
难度: 中等(Medium)
题目: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 <—
\
5 4 <—
You should return [1, 3, 4].
思路:其实就是按层次遍历,保留每层的最右边的结点
代码:
1 | def rightSideView(self, root): |
评论系统未开启,无法评论!