int result[1000];

int i=-1;

struct TreeNode* queue[1000];

int p=-1;

int q=-1;

int *_rightSideView(struct TreeNode *root, int *n){

int lay=0;

```
if(!root) return NULL;
queue[++p]=root;
while(q!=p){
struct TreeNode *temp;
temp=queue[++q];
if(temp->left) queue[++p]=temp->left;
if(temp->right) queue[++p]=temp->right;
if(q==lay){
*n=*n+1;
result[++i]=queue[lay]->val;
lay=p;
}
}
return result;
```

}

int *rightSideView(struct TreeNode *root, int *n) {

*n=0;

return _rightSideView(root,n);

}