class Solution(object):

    def rightSideView(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """

        def collect(node, depth):
            if node:
                if depth == len(vals):
                    vals.append(node.val)
                collect(node.right, depth + 1)
                collect(node.left, depth + 1)
        vals = []
        collect(root, 0)
        return vals

4bb0e9e47f0b7ff2fd4ae3a9b4925062537d7528
<mask token>

class Solution(object):
    <mask token>

class Solution(object):

    def rightSideView(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """

        def collect(node, depth):
            if node:
                if depth == len(vals):
                    vals.append(node.val)
                collect(node.right, depth + 1)
                collect(node.left, depth + 1)
        vals = []
        collect(root, 0)
        return vals
