Skip to content

Commit c1f06a8

Browse files
authored
Create 6 May Left View of Binary Tree (#788)
2 parents fe2d61a + 0bb7978 commit c1f06a8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

6 May Left View of Binary Tree

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
vector<int> leftView(Node *root) {
4+
// code here
5+
vector<int> result;
6+
if (!root) return result;
7+
8+
queue<Node*>q;
9+
q.push(root);
10+
11+
while(!q.empty()){
12+
13+
int n=q.size();
14+
Node* curr = q.front();
15+
result.push_back(curr->data);
16+
17+
while(n--){
18+
Node* x = q.front();
19+
q.pop();
20+
if(x->left)
21+
q.push(x->left);
22+
if(x->right)
23+
q.push(x->right);
24+
}
25+
}
26+
return result;
27+
}
28+
};
29+

0 commit comments

Comments
 (0)