```
def rightSideView(self, root):
answer = []
if not root:
return answer
stack = []
stack.append(root)
while len(stack) > 0:
n = len(stack)
queue = []
for i in range(n):
node = stack.pop()
if i == 0:
answer.append(node.val)
if node.right:
stack.insert(0, node.right)
if node.left:
stack.insert(0, node.left)
return answer
```