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 | For example: |
题意:
给定一棵二叉树,返回从右边看这棵二叉树所看到的节点序列(从上到下)。
思路:
层次遍历法,遍历到每层最后一个节点时,把其放到结果集中。
1 | struct TreeNode { |