-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRightViewOfTree.cpp
More file actions
36 lines (36 loc) · 832 Bytes
/
Copy pathRightViewOfTree.cpp
File metadata and controls
36 lines (36 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<bits/stdc++.h>
using namespace std;
class Node {
public:
int data;
Node* left = NULL;
Node* right = NULL;
};
class Solution
{
public:
//Function to return list containing elements of right view of binary tree.
vector<int> rightView(Node *root)
{
queue<Node*>q;
vector<int>FinalOutput;
q.push(root);
while(!q.empty()){
int sz = q.size();
int TemporaryValue = 0;
while(sz--){
auto p = q.front();
q.pop();
TemporaryValue = p->data;
if(p->left){
q.push(p->left);
}
if(p->right){
q.push(p->right);
}
}
FinalOutput.push_back(TemporaryValue);
}
return FinalOutput;
}
};