<p>Given the <code>root</code> of a binary tree, imagine yourself standing on the <strong>right side</strong> of it, return <em>the values of the nodes you can see ordered from top to bottom</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/14/tree.jpg" style="width: 401px; height: 301px;" />
<pre>
<strong>Input:</strong> root = [1,2,3,null,5,null,4]
<strong>Output:</strong> [1,3,4]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> root = [1,null,3]
<strong>Output:</strong> [1,3]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the tree is in the range <code>[0, 100]</code>.</li>
	<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    
    // vector<int> rightSideView(TreeNode* root) {
    //     vector<int> answer;
    //     if(root ==NULL)
    //     {return answer;}
    //     queue<TreeNode*> q;
    //     q.push(root);
    //     while(!q.empty())
    //     {
    //         int s = q.size();
    //         vector<int> v;
    //         for(int i=0; i<s; i++)
    //         {
    //             if(q.front()->left != NULL)
    //             {q.push(q.front()->left);}
    //             if(q.front()->right != NULL)
    //             {q.push(q.front()->right);}
    //             v.push_back(q.front()->val);
    //             q.pop();
    //         }
    //         answer.push_back(v[s-1]);
    //     }
    //     return answer;
    // }

    vector<int> ans;

    void inorder(TreeNode* node, int level) {
        if (!node) {
            return;
        }

        if(ans.size() == level) {
            ans.push_back(node->val);
        }
        inorder(node->right, level+1);
        inorder(node->left, level+1);
    }

    vector<int> rightSideView(TreeNode* root) {
        if(!root) return ans;
        inorder(root, 0);
        root->left=NULL;
        root->right=NULL;
        return ans;
    }
};
13600