KhushbooGoel01 / Top-Interview-Questions--Leetcode

These are codes for Top Interview Questions from Leetcode.
250 stars 139 forks source link

Binary Tree Right Side view using recursion traversal #51

Open jaybamroliya opened 3 years ago

jaybamroliya commented 3 years ago

There should be a Binary Tree Right Side view using recursion traversal

Code

class Solution { public: map<int, int> rightside; void find(TreeNode* root, int num){ if(root == NULL) return; rightside[num] = root->val; find(root->left, num+1); find(root->right, num+1); }

vector<int> rightSideView(TreeNode* root) {

    if(root == NULL) return {};
    find(root, 0);
    vector<int> ans;
    for(auto it: rightside){
        ans.push_back(it.second);
    }

    return ans; 
}

}

jaybamroliya commented 3 years ago

I want to work on this issue @KhushbooGoel01 .please assign this to me

KhushbooGoel01 commented 3 years ago

@jaybamroliya I don't understand the issue? please write issues carefully. Do you want to add this question? mention that. provide the link to the question.