# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def rightSideView(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        def right(level):
            if len(level) == 0:
                return []
            return [level[-1].val]+right([x for i in level for x in [i.left,i.right] if x])
        if not root:
            return []
        return right([root])

@https://github.com/Linzertorte/LeetCode-in-Python/blob/master/BinaryTreeRightSideView.py#L2

相关文章:

  • 2021-11-30
  • 2021-04-21
  • 2021-10-06
  • 2021-05-18
  • 2021-10-02
猜你喜欢
  • 2021-07-01
  • 2021-10-07
  • 2022-01-11
  • 2022-02-13
  • 2022-02-03
  • 2022-12-23
  • 2021-08-08
相关资源
相似解决方案