-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeftViewOfTree.cpp
More file actions
37 lines (34 loc) · 816 Bytes
/
Copy pathLeftViewOfTree.cpp
File metadata and controls
37 lines (34 loc) · 816 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
37
#include<bits/stdc++.h>
using namespace std;
class Node {
public:
int data;
Node* left = NULL;
Node* right = NULL;
};
vector<int> leftView(Node *root)
{
vector<int>FinalOutput;
if(root == NULL)return FinalOutput;
queue<Node*>q;
q.push(root);
while(!q.empty()){
int sz = q.size();
int TemporaryValue = 10001;
while(sz--){
auto CurrentNode = q.front();
q.pop();
if(TemporaryValue == 10001){
TemporaryValue = CurrentNode->data;
}
if(CurrentNode->left){
q.push(CurrentNode->left);
}
if(CurrentNode->right){
q.push(CurrentNode->right);
}
}
FinalOutput.push_back(TemporaryValue);
}
return FinalOutput;
}