Binary Tree Right Side View

Given the root of a binary tree, return the values of the nodes you can see from the right side, ordered from top to bottom. The tree is represented by its root node.

Constraints

  • The number of nodes in the tree is in the range [0, 100].
  • -100 <= Node.val <= 100
Auto-saved · 10 lines
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right

class Solution:
def rightSideView(self, root: Optional[TreeNode]) -> List[int]:

Console

Click Run to execute sample tests.