Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bottomViewBT(Node *root,map<int,map<int,vector<int>>> &mp,int hdis,int vdis){
- //base
- if(root==NULL)
- return ;
- mp[hdis][vdis].push_back(root->data);
- bottomViewBT(root->left,mp,hdis-1,vdis+1);
- bottomViewBT(root->right,mp,hdis+1,vdis+1);
- }
- vector<int> bottomView(Node* root) {
- map<int,map<int,vector<int>>> mp;
- bottomViewBT(root,mp,0,0);
- vector<int> res;
- for(auto i:mp){
- map<int,vector<int>> p=i.second;
- for(auto q=p.rbegin();q!=p.rend();q++) {
- vector<int> temp = q->second;
- res.push_back(temp[0]);
- break;
- }
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement