```
class Solution:
# @param {TreeNode} root
# @return {integer[]}
def rightSideView(self, root):
cur=[]
next=[]
result=[]
if root is None:
return []
cur.append(root)
result.append(root.val)
while len(cur)>0:
for x in cur:
if x.left:
next.append(x.left)
if x.right:
next.append(x.right)
cur = next
next = []
if len(cur)>0:
result.append(cur[-1].val)
return result
```