```
vector<int> res;
int max=-1;
void helper(TreeNode* root,int h){
if(root==NULL) return;
if(h>max){
res.push_back(root->val);
max=h;
}
helper(root->right,h+1);
helper(root->left,h+1);
}
vector<int> rightSideView(TreeNode* root) {
helper(root,0);
return res;
}
```