```
class Solution:
# @param {TreeNode} root
# @return {integer[]}
def rightSideView(self, root):
res = []
self.right_side_view_help(root, 0, [0], res)
return res
def right_side_view_help(self, root, curr, level, res):
if not root:
return
if curr >= level[0]:
res.append(root.val)
level[0] += 1
curr += 1
self.right_side_view_help(root.right, curr, level, res)
self.right_side_view_help(root.left, curr, level, res)
```