class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
vector<TreeNode* > a;
vector<int> re;
if(!root) return re;
a.push_back(root);
if(!root->left && !root->right) {re.push_back(root->val); return re;}
int l = 0 , r = 1;
while(l < r){
for(int i = l ; i < r; i++){
if(a[i]->left) a.push_back(a[i]->left);
if(a[i]->right) a.push_back(a[i]->right);
}
re.push_back(a[r-1]->val);
l = r;
r = a.size();
}
return re;
}
};