from collections import deque # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None
classSolution: defrightSideView(self, root): """ :type root: TreeNode :rtype: List[int] """ ifnot root:return [] q = deque() q.append(root) res = [] while q: n = len(q) for i in range(n): node = q.popleft() if i == 0:res.append(node.val) if node.right:q.append(node.right) if node.left:q.append(node.left) return res